ePages 6.10 - DE_EPAGES/Object/API/Object/Class.pm

Package DE_EPAGES::Object::API::Object::Class

object interface for Class.

Base
DE_EPAGES::Object::API::Object::Object

Functions

allDefaultAttributes
attribute
attributePackages
attributes
baseClass
baseClasses
className
cloneAttributes
dalObject
dbPackage
defaultAttributes
deleteAttribute
deleteObjects
directAttribute
directAttributes
directObjects
directSubClasses
existsAttribute
existsDirectAttribute
existsObject
findObjects
getObjects
insertAttribute
insertObject
insertSubClass
isSubClassOf
loadObject
multiObjects
objects
packageObject
subClasses
updateAttribute

allDefaultAttributes

Returns hash of default attribute values of this class (including undef for not defined defaults).

Syntax
$hValues = $Class->allDefaultAttributes($Parent, $hInfo);
Input
$Parent (object)
parent of new or existing object
$hInfo (ref.hash)
given parameter (optional)
Return
$hValues (ref.hash)
default attribute names and value pairs

attribute

Returns information about an attribute.

Syntax
$hAttribute = $Class->attribute( $Alias );
Input
$Alias (string)
attribute alias
Return
$Attribute (object)
attribute object, see class: Attribute

attributePackages

Returns all attribute packages and the corresponding attribute names.

Syntax
$haPackages = $Class->attributePackages
Return
$haPackages (ref.hash.array)
all packages and attributes as hash
  • { $PackageName => \@AttributeNames, ... }

attributes

Returns all attributes of a class, including inherited ones.

Syntax
$aAttributes = $Class->attributes;
Return
$aAttributes (reference to array of hash)
list of attributes, see attribute

baseClass

Returns the base class or undef if the class does not have a base class.

Syntax
$BaseClass = $Class->baseClass;
Return
$BaseClass (object)
base class

baseClasses

Returns all base classes recursively in ascending order, i.e. the Object class (which has no other base class) is the first array element. This array includes the given class as last element.

Syntax
$aBaseClasses = $Class->baseClasses;
Return
$aBaseClasses (reference to array of object)
list of base classes

className

Returns the class name, used for DAL access.

Syntax
$ClassName = $Class->className;
Return
$ClassName (String)
class name

cloneAttributes

call cloneAttribute for each attribute package

Syntax
$Class->cloneAttributes($Object, $Clone);
Input
$Object (object)
object to clone
$Clone (object)
copy of object

dalObject

Returns the dal (database abstration layer) of objects of this class, not of the class it self ($Class->dal).

Syntax
$DAL = $Class->dalObject;
Return
$DAL (object)
database abstraction layer

dbPackage

Returns the database package, used for DAL access.

Syntax
$DbPackage = $Class->dbPackage;
Return
$DbPackage (String)
database package name

defaultAttributes

Returns hash of default attribute values of this class.

Syntax
$hValues = $Class->defaultAttributes($Parent, $hInfo);
Input
$Parent (object)
parent of new or existing object
$hInfo (ref.hash)
(optional) additional parameters, passed through to
DE_EPAGES::Object::API::BaseAttribute::defaultAttributes
as extra parameter
Return
$hValues (ref.hash)
default attribute names and value pairs

deleteAttribute

Deletes an attribute from the class.

Syntax
$Deleted = $Class->deleteAttribute( $Alias );
Input
$Alias (string)
attribute alias
Return
$Deleted (boolean)
attribute was deleted

deleteObjects

Removes matching objects.

Syntax
$Class->deleteObjects($IndexName, $hParameter);
Input
$IndexName (string)
name of index
$hParameter (ref.hash)
parameter of index (see getObjects)
$aParameter (ref.array)
array of parameter in correct order

directAttribute

Returns the attribute object with this alias exists in the class and is defined in this class (not in a base class).

Syntax
$Attribute = $Class->directAttribute( $Alias )
Input
$Alias (string)
attribute alias
Return
$Exists (boolean)
true it the attribute exists

directAttributes

Returns all direct attributes of a class (not including inherited ones).

Syntax
$aAttributes = $Class->directAttributes;
Return
$aAttributes (reference to array of hash)
list of attributes, see attribute

directObjects

Returns all objects that are directly instanciated from this class.

Syntax
$aObjects = $Class->directObjects;
Example
$_->delete foreach @{ $Class->directObjects };
Return
$aObjects (array ref)
list of objects

directSubClasses

Returns all direct sub classes of a class (not recursively).

Syntax
$aSubClasses = $Class->directSubClasses;
Return
$aSubClasses (reference to array of object)
list of sub classes

existsAttribute

Returns true if an attribute with this name exists in the class.

Syntax
$Exists = $Class->existsAttribute( $Alias )
Example
if( $Class->existsAttribute( 'MinOrderLevel' ) ) { ... }
Input
$Name (string)
attribute name
Return
$Exists (boolean)
true it the attribute exists

existsDirectAttribute

Returns true if an attribute with this alias exists in the class and is defined in this class (not in a base class).

Syntax
$Exists = $Class->existsDirectAttribute( $Alias )
Example
if( $Class->existsDirectAttribute( 'MinOrderLevel' ) ) { ... }
Input
$Alias (string)
attribute alias
Return
$Exists (boolean)
true it the attribute exists

existsObject

Returns true if the object of this class exists in the database.

Syntax
$Exists = $Class->existsObject($ObjectID);
Input
$ObjectID (integer)
Object ID
Return
$Object (object)
object

findObjects

Returns matching objects identifiers by index.

Syntax
$aObjectIDs = $Class->findObjects($IndexName, $hParameter);
Input
$IndexName (string)
name of index
$hParameter (ref.hash)
parameter of index (see getObjects)
Return
$aObjectIDs (ref.array.int)
object identifier of this class matches condition

getObjects

Returns matching objects by index.

Syntax
$aObjects = $Class->getObjects($IndexName, $hParameter);
$aObjects = $Class->getObjects($IndexName, $aParameter);
$aObjects = $Class->getObjects('ByParentID', {
    ObjectID => $ObjectID,
    Alias => $Alias,
});
Example
$Class = LoadClassByAlias('Object');
$aObjects = $Class->getObjects('ByParentID', [$ObjectID]);
$aObjects = $Class->getObjects('ByParentID', [$ObjectID, $Alias]);
Input
$IndexName (string)
name of index
$hParameter (ref.hash)
parameter of index
$aParameter (ref.array)
array of parameter in correct order
Return
$aObjects (ref.array.object)
objects of this class matches condition

insertAttribute

Adds a new attribute to the class.

Syntax
$Class->insertAttribute( $hAttribute );
Input
$hAttribute (reference to hash)
The hash contains these keys:
  • Alias - attribute alias - varchar(255)
  • Type - data type name - varchar(30)
  • Length - maximum length (optional)- int
  • Package - package name - varchar(255)
  • IsArray - array attribute (optional, default=0) - boolean
  • IsReadOnly - read only (optional, default=0) - boolean
  • IsExportable - include in export files (optional, default=1) - boolean
Return
$Attribute (object)
new attribute

insertObject

Creates a new object instance of this class with the given attribute values.

Syntax
$Object = $Class->insertObject($hValues);
Example
$Product = $ProductType->insertObject({
    Parent => $Shop->child('Products'),
    Alias  => '08/15',
});
Input
$hValues (ref.hash)
attribute name => value hash
Return
$Object (object)
object

insertSubClass

Creates a new sub class. The default package is 'DE_EPAGES::Object::API::Object::Object'.

Syntax
$SubClass = $Class->insertSubClass($hClass);
Input
$hClass (reference to hash)
with following keys:
  • Alias - class alias - varchar(255)
  • Package - attribute package for class (optional) - varchar(255)
Return
$Class (object)
class object

isSubClassOf

Returns true if the class is a sub class of the class or one of its sub classes.

Syntax
$IsSubClass = $Class->isSubClassOf( $Class )
$IsSubClass = $Class->isSubClassOf( $ClassName )
Example
my $ClassProduct = LoadClassByAlias( 'Product' );
if( $Class->isSubClassOf( $ClassProduct ) ) { ... }
if( $Class->isSubClassOf('Product' ) ) { ... }
Input
$ClassName (object)
name of class (or object of class) | string
Return
$IsSubClass (boolean)
true if the class is a sub class of the class

loadObject

Returns object from id of this class.

Syntax
$Object = $Class->loadObject($ObjectID, $LoadIt);
Input
$ObjectID (integer)
Object ID
$LoadIt (boolean)
load via package (not via LoadObject)
Return
$Object (object)
object

multiObjects

Returns multiple objects by object id.

Syntax
$aObjects = $Class->multiObjects($aIDs);
Input
$aIDs (ref.array.int)
identifier
Return
$aObjects (ref.array.object)
objects of this class matches condition

objects

Returns all objects that are direct or indirect instances of this class.

Syntax
$aObjects = $Class->objects;
Example
$_->delete foreach @{ $Class->objects };
Return
$aObjects (array ref)
list of objects

packageObject

Returns the perl package of objects of this class. The returned package was imported via use before.

Syntax
$Package = $Class->packageObject;
Return
$Package (string)
perl package name

subClasses

Returns all known sub classes of a class recursively.

Syntax
$aSubClasses = $Class->subClasses;
Return
$aSubClasses (reference to array of object)
list of sub classes

updateAttribute

Updates properties of an attribute.

Syntax
$Class->updateAttribute( $Alias, $hAttribute );
Input
$Name (string)
attribute name
$hAttribute (reference to hash)
attribute properties, see insertAttribute