Class::meta class constructor introspection
# Assuming MyApp::Thingy was generated by Class::Meta. my $class = MyApp::Thingy->my_class; print "\nConstructors:\n"; for my $ctor ($class->constructors) { print " o ", $ctor->name, $/; my $thingy = $ctor->call($class->package); }
This class provides an interface to the \*(C`Class::Meta\*(C' objects that describe class constructors. It supports a simple description of the constructor, a label, and the constructor visibility (private, protected, trusted,or public).
Class::Meta::Constructor objects are created by Class::Meta; they are never instantiated directly in client code. To access the constructor objects for a Class::Meta-generated class, simply call its \*(C`my_class()\*(C' method to retrieve its Class::Meta::Class object, and then call the \*(C`constructors()\*(C' method on the Class::Meta::Class object.
new
A protected method for constructing a Class::Meta::Constructor object. Do not call this method directly; Call the \*(C`add_constructor()\*(C' method on a Class::Meta object, instead.
name
my $name = $ctor->name;
Returns the constructor name.
package
my $package = $ctor->package;
Returns the package name of the class that constructor is associated with.
desc
my $desc = $ctor->desc;
Returns the description of the constructor.
label
my $desc = $ctor->label;
Returns label for the constructor.
view
my $view = $ctor->view;
Returns the view of the constructor, reflecting its visibility. The possible values are defined by the following constants:
class
my $class = $ctor->class;
Returns the Class::Meta::Class object that this constructor is associated with. Note that this object will always represent the class in which the constructor is defined, and not any of its subclasses.
call
my $obj = $ctor->call($package, @params);
Executes the constructor. Pass in the name of the class for which it is being executed (since, thanks to subclassing, it may be different than the class with which the constructor is associated). All other parameters will be passed to the constructor. Note that it uses a \*(C`goto\*(C' to execute the constructor, so the call to \*(C`call()\*(C' itself will not appear in a call stack trace.
build
$ctor->build($class);
This is a protected method, designed to be called only by the Class::Meta class or a subclass of Class::Meta. It takes a single argument, the Class::Meta::Class object for the class in which the constructor was defined, and generates constructor method for the Class::Meta::Constructor, either by installing the code reference passed in the \*(C`code\*(C' parameter or by creating the constructor from scratch.
Although you should never call this method directly, subclasses of Class::Meta::Constructor may need to override its behavior.
Please send bug reports to <[email protected]> or report them via the \s-1CPAN\s0 Request Tracker at http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Meta <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Meta>.
This module is stored in an open GitHub repository <http://github.com/theory/class-meta/>. Feel free to fork and contribute!
Please file bug reports via GitHub Issues <http://github.com/theory/class-meta/issues/> or by sending mail to [email protected] <mailto:[email protected]>.
David E. Wheeler <[email protected]>
Other classes of interest within the Class::Meta distribution include:
Copyright (c) 2002-2011, David E. Wheeler. Some Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.