NAME

Abstract::Meta::Attribute - Meta object attribute.

SYNOPSIS

    use Abstract::Meta::Class ':all';
    has '$.attr1' => (default => 0);    

DESCRIPTION

An object that describes an attribute. It includes required, data type, association validation, default value, lazy retrieval. Name of attribute must begin with one of the follwoing prefix: $. => Scalar, @. => Array, %. => Hash, &. => Code,

EXPORT

None.

METHODS

new
initialise

Initialises attribute

name

Returns attribute name

class

Attribute's class name.

storage_key

Returns storage attribute key in object

perl_type

Returns attribute type, Scalar, Hash, Array, Code

accessor

Returns accessor name

mutator

Returns mutator name

required

Returns required flag

default

Returns default value

storage_type

Hash|Array

transistent

If this flag is set, than storage of that attribte, will be force outside the object, so you cant serialize that attribute, It is especially useful when using callback, that cant be serialised (Storable dclone) This option will generate cleanup and DESTORY methods.

item_accessor

Returns name that will be used to construct the hash or array item accessor. It will be used to retrieve or set array or hash item item

has '%.items' => (item_accessor => 'item'); ... my $item_ref = $obj->items; $obj->item(x => 3); my $value = $obj->item('y')'

associated_class

Return name of the associated class.

index_by

Name of the asscessor theat will return unique attribute for associated objects. Only for toMany associaion, by deault uses objecy reference as index.

package Class; use Abstract::Meta::Class ':all'; has '$.name' => (required => 1); has '%.details' => ( index_by => 'id', item_accessor => 'detail', ); my $obj = Class->

the_other_end

Name of the asscessor/mutator on associated class to keep bideriectional association This option will generate cleanup method.

data_type_validation

Flag that turn on/off data type validation. Data type validation happens when using association_class or Array or Hash data type unless you explicitly disable it by seting data_type_validation => 0.

on_read

Returns code reference that will be replace data read routine

    has '%.attrs.' => (
        item_accessor => 'attr'
        on_read => sub {
            my ($self, $attribute, $scope, $key) = @_;
            my $values = $attribute->get_values($self);
            if ($scope eq 'accessor') {
                return $values;
            } else {
                return $values->{$key};
            }
        },
    );
    has '@.array_attrs.' => (
        item_accessor => 'array_item'
        on_read => sub {
            my ($self, $attribute, $scope, $index) = @_;
            my $values = $attribute->get_values($self);
            if ($scope eq 'accessor') {
                return $values;
            } else {
                return $values->[$index];
            }
        },
    );
set_on_read

Sets code reference that will be replace data read routine

   my $attr = MyClass->meta->attribute('attrs'); 
    $attr->set_on_read(sub {
        my ($self, $attribute, $scope, $key) = @_;
        #do some stuff
    });
on_change

Code reference that will be executed when data is set, Takes reference to the variable to be set.

set_on_change

Sets code reference that will be executed when data is set,

   my $attr = MyClass->meta->attribute('attrs'); 
   $attr->set_on_change(sub {
           my ($self, $attribute, $scope, $value, $key) = @_;
            if($scope eq 'mutator') {
                my $hash = $$value;
                foreach my $k (keys %$hash) {
                    #  do some stuff
                    #$self->validate_trigger($k, $hash->{$k});
                }
            } else {
                # do some stuff
                $self->validate_trigger($key. $$value);
            }
            $self;      
    });
on_validate

Returns on validate code reference. It is executed before the data type validation happens.

set_on_validate

Sets code reference that will be replace data read routine

   my $attr = MyClass->meta->attribute('attrs'); 
    $attr->set_on_read(sub {
        my ($self, $attribute, $scope, $key) = @_;
        #do some stuff
    });

SEE ALSO

Abstract::Meta::Class.

COPYRIGHT AND LICENSE

The Abstract::Meta::Attribute module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.

AUTHOR

Adrian Witas, adrian@webapp.strefa.pl