man Class::Meta::Method () - Class::Meta class method introspection
NAME
Class::Meta::Method - Class::Meta class method introspection
SYNOPSIS
# Assuming MyApp::Thingy was generated by Class::Meta. my $class = MyApp::Thingy->my_class; my $thingy = MyApp::Thingy->new;
print "\nMethods:\n"; for my $meth ($class->methods) { print " o ", $meth->name, $/; $meth->call($thingy); }
DESCRIPTION
This class provides an interface to the CWClass::Meta objects that describe methods. It supports a simple description of the method, a label, and its visibility (private, protected, trusted, or public).
Class::Meta::Method objects are created by Class::Meta; they are never instantiated directly in client code. To access the method objects for a Class::Meta-generated class, simply call its CWmy_class() method to retrieve its Class::Meta::Class object, and then call the CWmethods() method on the Class::Meta::Class object.
INTERFACE
Constructors
new
A protected method for constructing a Class::Meta::Method object. Do not call this method directly; Call the CWadd_method() method on a Class::Meta object, instead.
Instance Methods
name
my $name = $meth->name;
Returns the method name.
package
my $package = $meth->package;
Returns the method package.
desc
my $desc = $meth->desc;
Returns the description of the method.
label
my $desc = $meth->label;
Returns label for the method.
view
my $view = $meth->view;
Returns the view of the method, reflecting its visibility. The possible values are defined by the following constants:
- Class::Meta::PUBLIC
- Class::Meta::PRIVATE
- Class::Meta::TRUSTED
- Class::Meta::PROTECTED
context
my $context = $meth->context;
Returns the context of the method, essentially whether it is a class or object method. The possible values are defined by the following constants:
- Class::Meta::CLASS
- Class::Meta::OBJECT
args
A description of the arguments to the method. This can be anything you like, but I recommend something like a string for a single argument, an array reference for a list of arguments, or a hash reference for parameter arguments.
returns
A description of the return value or values of the method.
class
my $class = $meth->class;
Returns the Class::Meta::Class object that this method is associated with. Note that this object will always represent the class in which the method is defined, and not any of its subclasses.
call
my $ret = $meth->call($obj, @args);
Calls the method on the CW$obj object, passing in any arguments. Note that it uses a CWgoto to execute the method, so the call to CWcall() itself will not appear in a call stack trace.
build
$meth->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 method was defined. Once it checks to make sure that it is only called by Class::Meta or a subclass of Class::Meta or of Class::Meta::Method, CWCbuild() installs the method if it was specified via the CWcode parameter to CWnew().
Although you should never call this method directly, subclasses of Class::Meta::Method may need to override it in order to add behavior.
BUGS
Please send bug reports to <bug-class-meta@rt.cpan.org> or report them via the CPAN Request Tracker at <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Meta>.
AUTHOR
David Wheeler <david@kineticode.com>
SEE ALSO
Other classes of interest within the Class::Meta distribution include:
- Class::Meta
- Class::Meta::Class
- Class::Meta::Constructor
- Class::Meta::Attribute
COPYRIGHT AND LICENSE
Copyright (c) 2002-2005, David Wheeler. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.