Abstract-Meta-Class
view release on metacpan or search on metacpan
lib/Abstract/Meta/Attribute/Method.pm view on Meta::CPAN
}
=item pending_transation
=cut
{ my %pending_association;
=item start_association_process
Start association process (to avoid infinitive look of associating the others ends)
Takes obj reference.
=cut
sub start_association_process {
my ($self) = @_;
$pending_association{$self} = 1;
}
=item has_pending_association
Returns true is object is during association process.
=cut
sub has_pending_association {
my ($self) = @_;
$pending_association{$self};
}
=item end_association_process
Compleetes association process.
=cut
sub end_association_process {
my ($self) = @_;
delete $pending_association{$self};
}
}
=item associate_the_other_end
Associate current object reference to the the other end associated class.
lib/Abstract/Meta/Attribute/Method.pm view on Meta::CPAN
my $associated_class = $attr->associated_class;
my $the_other_end_attribute = $associated_class->meta->attribute($the_other_end);
confess "missing other end attribute on ". ref($value) . "::" . $the_other_end
unless $the_other_end_attribute;
confess "invalid definition for " . ref($self) ."::". $name
. " - associatied class not defined on " . ref($value) ."::" . $the_other_end
unless $the_other_end_attribute->associated_class;
start_association_process($value);
eval {
my $association_call = 'associate_' . lc($the_other_end_attribute->perl_type) . '_as_the_other_end';
$attr->$association_call($self, $value);
};
end_association_process($value);
die $@ if $@;
}
=item associate_scalar_as_the_other_end
=cut
sub associate_scalar_as_the_other_end {
lib/Abstract/Meta/Attribute/Method.pm view on Meta::CPAN
=cut
sub deassociate {
my ($attr, $self) = @_;
my $transistent = $attr->transistent;
my $storage_key = $attr->storage_key;
my $array_storage_type = $attr->storage_type eq 'Array';
my $value = ($transistent ? get_attribute($self, $storage_key) : ($array_storage_type ? $self->[$storage_key] : $self->{$storage_key})) or return;
my $the_other_end = $attr->the_other_end;
return if ! $the_other_end || has_pending_association($value);
start_association_process($self);
my $associated_class = $attr->associated_class;
my $the_other_end_attribute = $associated_class->meta->attribute($the_other_end);
my $deassociation_call = 'deassociate_' . lc($the_other_end_attribute->perl_type) . '_as_the_other_end';
if(ref($value) eq 'ARRAY') {
$the_other_end_attribute->$deassociation_call($self, $_) for @$value;
} elsif(ref($value) eq 'HASH') {
$the_other_end_attribute->$deassociation_call($self, $value->{$_}) for(keys %$value);
} else {
$the_other_end_attribute->$deassociation_call($self, $value);
}
end_association_process($self);
}
=item deassociate_scalar_as_the_other_end
=cut
sub deassociate_scalar_as_the_other_end {
my ($attr, $self, $the_other_end_obj) = @_;
$the_other_end_obj or return;
lib/Abstract/Meta/Class.pm view on Meta::CPAN
package Triggers;
use Abstract::Meta::Class ':all';
has '@.y' => (
on_change => sub {
my ($self, $attribute_name, $scope, $value_ref, $index) = @_;
# scope -> mutator, item_accessor
... do some stuff
# process further in standard way by returning true
$self;
},
# replaces standard read
on_read => sub {
my ($self, $attr_name, $scope, $index)
#scope can be: item_accessor, accessor
...
#return requested value
},
item_accessor => 'y_item'
( run in 0.260 second using v1.01-cache-2.11-cpan-8d75d55dd25 )