NAME
Class::IntrospectionMethods::Parent - Handles parent relationship for Class::IntrospectionMethods
SYNOPSIS
No synopsis. Directly used by Class::IntrospectionMethods
DESCRIPTION
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)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
.
Exported functions
set_parent_method_name( name )
This function changes the name of the function and attribute names installed by graft_parent_method
. (cim_parent
by default)
graft_parent_method( child, parent, slot, [index] )
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.
ParentInfo class
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:
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.
index_value
Identical to index_value. This method may be preferred for hash based slots. (This is just syntactical sugar).
slot_name
Returns the name of the IntrospectionMethods slot containing the child object.
parent
Returns the parent object containing child.
EXAMPLE
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
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.
SEE ALSO
L<Class::IntrospectionMethods>