Class::IntrospectionMethods::Parent - Handles parent relationship for Class::IntrospectionMethods


Class-IntrospectionMethods documentation  | view source Contained in the Class-IntrospectionMethods distribution.

Index


NAME

Top

Class::IntrospectionMethods::Parent - Handles parent relationship for Class::IntrospectionMethods

SYNOPSIS

Top

 No synopsis. Directly used by Class::IntrospectionMethods

DESCRIPTION

Top

This class handles parent relationship for Class::IntrospectionMethods.

In other word, for any child object managed by Class::IntrospectionMethods, it will :

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

Top

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

Top

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

Top

 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

Top

SEE ALSO

Top

  L<Class::IntrospectionMethods>


Class-IntrospectionMethods documentation  | view source Contained in the Class-IntrospectionMethods distribution.