Dominique Dumont > Class-IntrospectionMethods-1.003 > Class::IntrospectionMethods::Parent

Download:
Class-IntrospectionMethods-1.003.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.003   Source  

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 :

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>
syntax highlighting: