Murat Ünalan > Class-Maker-0.5.14 > Maker/Basic/Reflection.pm

Download:
Class-Maker-0.5.14.tar.gz

Annotate this POD

CPAN RT

New  1
Open  2
View/Report Bugs
Source   Latest Release: Class-Maker-0.05.18

SYNOPSIS ^

        {
                package Human::Role;

                Class::Maker::class
                {
                        public =>
                        {
                                string => [qw( name desc )],
                        },

                        default =>
                        {
                                name => 'Role Name',

                                desc => 'Role Descrition',
                        },
                };

                sub anew : method
                {
                        my $this = shift;

                        return $this->new( name => $_[0] );
                }

        }

        {
                package Human::Role::Simple;

                @ISA = qw(Human::Role);

                sub new : method
                {
                        my $this = shift;

                        return $this->SUPER::new( name => $_[0] );
                }
        }

reflect ^

        Now a Class::Maker::Reflex object is returned (btw it is not created with Class::Maker):

                ->{parents} = href with all ->{isa} classes reflexes (only if $DEEP is true).

                ->{methods} = aref of ': method' functions of that package

                ->{def} = the original class definition (undef if not created with Class::Maker)

                ->{isa} = the actual @ISA value of the class package

                ->{name} = name of the reflected class

find ^

Returns a snapshot aref to all instances (objects) of a class in a given package.

CAVEAT: It only finds instance variables not created with 'my'

Example:

                # finds all objects which are return true for ->isa( 'Human' ) in the 'main' package

        my $aref_humans = Class::Maker::Reflection::find( 'main' => 'Human' );

Comment:

This function is extremly inefficient, because it is traversing the complete symbol table instead of maintaning a registry of the classes/objects. This seems the lessest error-prone approach, and the time will show if there will be need for efficients.

Function classes ^

        classes( fakultativ $scalref_mainpackage, [ $package ], .. );

 Purpose

        Traverses the symbol table and find "reflectable" classes.      Returns a list of hash references containing:

                "package_identifier" => $HREF_CLASS_HASH

        Meaning it gets references to the reflection of the class.

        { 'main::MyClass' => $href_myclass }, { 'main::YourClass' => $href_yclass }, ..
syntax highlighting: