GX::Meta::Class

Module Version: 0.2000_01

NAME

GX::Meta::Class - Class metaclass

SYNOPSIS

None.

DESCRIPTION

This module provides the GX::Meta::Class class.

METHODS

Constructor

new

Returns a GX::Meta::Class metaobject representing the specified class.

$class = GX::Meta::Class->new( %attributes );
Attributes:
  • name ( string ) [ required ]

    The name of the class, for example "My::Class".

Returns:
Exceptions:

Alternative syntax:

$class = GX::Meta::Class->new( $name );
Arguments:
  • $name ( string )

    The name of the class, for example "My::Class".

Returns:
Exceptions:

Public Methods

add_attribute

Adds the given attribute metaobject to the class.

$class->add_attribute( $attribute );
Arguments:
Exceptions:

Alternatively, a list of named arguments can be passed to add_attribute(). The given arguments are passed through to the GX::Meta::Attribute universal constructor to create a new attribute metaobject which is then added to the class.

$attribute = $class->add_attribute( %arguments );
Arguments:
Returns:
Exceptions:

add_code_attribute

Adds the given code attribute to the list of allowed code attributes for the class.

$class->add_code_attribute( $code_attribute );
Arguments:
  • $code_attribute ( string )

    A code attribute, which must be a simple name. See attributes for details.

Exceptions:

add_method

Adds a method to the class.

$class->add_method( $method_name, $code_reference );
Arguments:
  • $method_name ( string )
  • $code_reference ( CODE reference )
Exceptions:

all_attributes

Returns all attribute metaobjects.

@attributes = $class->all_attributes;
Returns:

all_class_attributes

Returns all class attribute metaobjects.

@attributes = $class->all_class_attributes;
Returns:

all_code_attributes

Returns the allowed code attributes for the class, including those allowed through inheritance.

@code_attributes = $class->all_code_attributes;
Returns:
  • @code_attributes ( strings )

    A list of simple names. See attributes for details.

all_instance_attributes

Returns all instance attribute metaobjects.

@attributes = $class->all_instance_attributes;
Returns:

all_methods

Returns a list of method metaobjects representing all the methods of the class, including the inherited ones.

@methods = $class->all_methods;
Returns:

all_methods_with_code_attribute

Does the same as all_methods(), but filters out all methods without the specified code attribute.

@methods = $class->all_methods_with_code_attribute( $code_attribute );
Arguments:
  • $code_attribute ( string )

    A simple name. See attributes for details.

Returns:
Exceptions:

all_subclasses

Returns a list of class metaobjects representing the direct and indirect subclasses of the class.

@classes = $class->all_subclasses;
Returns:

all_superclasses

Returns a list of class metaobjects representing the direct and indirect superclasses of the class.

@classes = $class->all_superclasses;
Returns:

attribute

Returns an associated attribute metaobject by the represented attribute's name, or undef if the class has no such (non-inherited) attribute.

$attribute = $class->attribute( $attribute_name );
Arguments:
  • $attribute_name ( string )
Returns:

attributes

Returns all non-inherited attribute metaobjects.

@attributes = $class->attributes;
Returns:

class_attributes

Returns all non-inherited class attribute metaobjects.

@attributes = $class->class_attributes;
Returns:

class_data

Returns a reference to the class data hash.

$data = $class->class_data;
Returns:
  • $data ( HASH reference )

class_data_identifier

Returns the identifier that is used for storing the class data hash in the symbol table.

$identifier = $class->class_data_identifier;
Returns:
  • $identifier ( string )

    Defaults to "CLASS_DATA".

code_attributes

Returns the allowed code attributes for the class, not including those allowed through inheritance.

@code_attributes = $class->code_attributes;
Returns:
  • @code_attributes ( strings )

    A list of simple names. See attributes for details.

destroy

Destroys the metaobject.

$class->destroy;

has_attribute

Returns true if the class has a non-inherited attribute with the given name, otherwise false.

$result = $class->has_attribute( $attribute_name );
Arguments:
  • $attribute_name ( string )
Returns:
  • $result ( bool )

has_method

Returns true if the class has a non-inherited method with the given name, otherwise false.

$result = $class->has_method( $method_name );
Arguments:
  • $method_name ( string )
Returns:
  • $result ( bool )

inherit_from

Prepends the specified classes to the @ISA array of the class.

$class->inherit_from( @classes );
Arguments:
  • @classes ( GX::Meta::Class objects | strings )

    Class metaobjects and / or class names.

Exceptions:

inherited_methods

Returns a list of method metaobjects representing the methods that the class inherits.

@methods = $class->inherited_methods;
Returns:

instance_attributes

Returns all non-inherited instance attribute metaobjects.

@attributes = $class->instance_attributes;
Returns:

linearized_isa

Returns a list with the names of all the classes that would be searched when resolving a method call on the represented class, starting with the represented class itself.

@class_names = $class->linearized_isa;
Returns:
  • @class_names ( strings )

linearized_isa_classes

Does the same as linearized_isa(), but returns class metaobjects instead of class names.

@classes = $class->linearized_isa_classes;
Returns:

method

Returns a method metaobject representing the non-inherited method with the given name, or undef if the class has no such method.

$method = $class->method( $method_name );
Arguments:
  • $method_name ( string )
Returns:

method_names

Returns the names of the non-inherited methods of the class.

@method_names = $class->method_names;
Returns:
  • @method_names ( strings )

methods

Returns a list of method metaobjects representing the non-inherited methods of the class.

@methods = $class->methods;
Returns:

methods_with_code_attribute

Does the same as methods(), but filters out all methods without the given code attribute.

@methods = $class->methods_with_code_attribute( $code_attribute );
Arguments:
  • $code_attribute ( string )

    A simple name. See attributes for details.

Returns:
Exceptions:

name

Returns the name of the class.

$name = $class->name;
Returns:
  • $name ( string )

package

Returns the associated package metaobject.

$package = $class->package;
Returns:

remove_method

Removes the specfied method.

$class->remove_method( $method_name );
Arguments:
  • $method_name ( string )
Exceptions:

subclasses

Returns a list of class metaobjects representing the direct subclasses of the class.

@classes = $class->subclasses;
Returns:

superclasses

Returns a list of class metaobjects representing the direct superclasses of the class, i.e. the classes in the @ISA array of the class.

@classes = $class->superclasses;
Returns:

If called with arguments, superclasses() sets the @ISA array of the represented class.

$class->superclasses( @classes );
Arguments:
  • @classes ( GX::Meta::Class objects | strings )

    Class metaobjects and / or class names.

Exceptions:

Internal Methods

code_attribute_store

Internal method.

$store = $class->code_attribute_store;
Returns:
  • $store ( HASH reference )

SEE ALSO

AUTHOR

Jörg A. Uzarek <uzarek@runlevelnull.de>

COPYRIGHT AND LICENSE

Copyright © 2009-2011 Jörg A. Uzarek.

This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation.