Class::IntrospectionMethods::Parent - Handles parent relationship for Class::IntrospectionMethods
No synopsis. Directly used by Class::IntrospectionMethods
This class handles parent relationship for Class::IntrospectionMethods.
In other word, for any child object managed by Class::IntrospectionMethods, it will :
Create a ParentInfo object that contains
the parent object ref (weakened by Scalar::Util weaken function)
weaken
The slot name containing the child
The index of the element containing the child if the slot is array or hash based.
Install a function/method in child's class to retrieve the ParentInfo object.
An attribute in child to store the ParentInfo's ref.
By default, the name of the installed function and arribute is cim_parent but this can be changed by calling set_parent_method_name.
cim_parent
set_parent_method_name
This function changes the name of the function and attribute names installed by graft_parent_method. (cim_parent by default)
graft_parent_method
Creates the ParentInfo object, install the cim_parent function in child's class, store the ParentInfo in child object, finally store slot and index in ParentInfo object.
A ParentInfo object is created each time the graft_parent_method function is called.
When, needed, this object is retrieved by calling:
$child->cim_parent
The the following methods may be applied to retrive the informations stored durung graft_parent_method call:
Returns the index value of the element containing the child object. Returns undex if the Class::IntrospectionMethods slot is not hash or array based.
Identical to index_value. This method may be preferred for hash based slots. (This is just syntactical sugar).
Returns the name of the IntrospectionMethods slot containing the child object.
Returns the parent object containing child.
package X ; use Class::IntrospectionMethods qw/make_methods set_parent_method_name/; set_parent_method_name('metadad') ; make_methods ( 'parent', hash => [ a => { tie_hash => ['MyHash', dummy => 'booh'], class_storage => ['MyObj', 'a' => 'foo'] }, ], new => 'new' ); package main; my $o = new X; my $obj = $o->a('foo') ; my $info = $obj->metadad ; my $p= $info->parent; # $p is $o print $info->slot_name; # -> 'a' print $info->index_value; # -> 'foo' # check parent method on object behind tied hash my $tied_hash_obj = $o->tied_hash_a ; my $p2 = $tied_hash_obj->metadad->parent; # $p2 is $o
Copyright (c) 2004 Dominique Dumont. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
L<Class::IntrospectionMethods>
To install Class::IntrospectionMethods, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::IntrospectionMethods
CPAN shell
perl -MCPAN -e shell install Class::IntrospectionMethods
For more information on module installation, please visit the detailed CPAN module installation guide.