Class-IntrospectionMethods
view release on metacpan or search on metacpan
IntrospectionMethods.pm view on Meta::CPAN
use vars qw( $VERSION @ISA @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(make_methods set_obsolete_behavior set_parent_method_name);
# Utility -----------------------------
# Necessary for parent feature
use Scalar::Util qw(isweak weaken) ;
use Class::IntrospectionMethods::Catalog
qw/set_global_catalog set_method_info set_method_in_catalog/;
use Class::IntrospectionMethods::Parent
qw/set_parent_method_name graft_parent_method/ ;
use Carp qw( carp cluck croak );
my $obsolete_behavior = 'carp' ;
my $support_legacy = 0 ;
my $legacy_object_init = 'cmm_init' ;
=over
=item *
Create a ParentInfo object that contains
=over
=item *
the parent object ref (weakened by L<Scalar::Util> C<weaken> function)
=item *
The slot name containing the child
=item *
The index of the element containing the child if the slot is array or
hash based.
When, needed, this object is retrieved by calling:
$child->cim_parent
The the following methods may be applied to retrive the informations
stored durung C<graft_parent_method> call:
=cut
package Class::IntrospectionMethods::ParentInfo ;
use Scalar::Util qw(isweak weaken) ;
sub new
{
my $type = shift;
my $self = {@_ };
# Necessary to avoid ghost object and memory leaks. See
# WeakRef module See also "Programming perl" 3rd edition
# page 266.
weaken ($self -> {parent}) ;
bless $self,$type ;
}
=head2 index_value
Returns the index value of the element containing the child object.
Returns undex if the Class::IntrospectionMethods slot is not hash or
array based.
=cut
sub parent
{
my $self = shift ;
my $parent = shift ;
if (defined $parent)
{
# Necessary to avoid ghost object and memory leaks. See
# WeakRef module See also "Programming perl" 3rd edition
# page 266.
weaken ($self -> {parent} = $parent) ;
}
return $self->{parent}
}
# This class is provided for backward compatibility for an older
# projet (the one that used a modified version of Class::MethodMaker)
# Do not use.
package Class::IntrospectionMethods::ParentNameTie ;
( run in 0.713 second using v1.01-cache-2.11-cpan-65fba6d93b7 )