1MakeMethods::Attribute(U3s)er Contributed Perl DocumentatMiaokneMethods::Attribute(3)
2
3
4

NAME

6       Class::MakeMethods::Attribute - Declare generated subs with attribute
7       syntax
8

SYNOPSIS

10         package MyObject;
11         use Class::MakeMethods::Attribute 'Standard::Hash';
12
13         sub new    :MakeMethod('new');
14         sub foo    :MakeMethod('scalar');
15         sub bar    :MakeMethod('scalar', { hashkey => 'bar_data' });
16         sub debug  :MakeMethod('Standard::Global:scalar');
17

DESCRIPTION

19       This package allows common types of methods to be generated via a sub‐
20       routine attribute declaration. (Available in Perl 5.6 and later.)
21
22       Adding the :MakeMethod() attribute to a subroutine declaration causes
23       Class::MakeMethods to create and install a subroutine based on the
24       parameters given to the :MakeMethod attribute.
25
26       You can declare a default method-generation class by passing the name
27       of a MakeMethods subclass in the use Class::MakeMethods::Attribute
28       statement. This default method-generation class will also apply as the
29       default to any subclasses declared at compile time. If no default
30       method-generation class is selected, you will need to fully-qualify all
31       method type declarations.
32

EXAMPLE

34       Here's a typical use of Class::MakeMethods::Attribute:
35
36         package MyObject;
37         use Class::MakeMethods::Attribute 'Standard::Hash';
38
39         sub new    :MakeMethod('new');
40         sub foo    :MakeMethod('scalar');
41         sub bar    :MakeMethod('scalar', { hashkey => 'bar_data' });
42         sub debug  :MakeMethod('Standard::Global:scalar');
43
44         package MySubclass;
45         use base 'MyObject';
46
47         sub bazzle :MakeMethod('scalar');
48
49       This is equivalent to the following explicit Class::MakeMethods invoca‐
50       tions:
51
52         package MyObject;
53
54         use Class::MakeMethods (
55           -MakerClass => 'Standard::Hash',
56           new => 'new',
57           scalar => 'foo',
58           scalar => [ 'ba', { hashkey => 'bar_data' } ],
59           'Standard::Global:scalar' => 'debug',
60         );
61
62         package MySubclass;
63         use base 'MyObject';
64
65         use Class::MakeMethods (
66           -MakerClass => 'Standard::Hash',
67           scalar => 'bazzle',
68         );
69

DIAGNOSTICS

71       The following warnings and errors may be produced when using
72       Class::MakeMethods::Attribute to generate methods. (Note that this list
73       does not include run-time messages produced by calling the generated
74       methods, or the standard messages produced by Class::MakeMethods.)
75
76       Can't apply MakeMethod attribute to %s declaration.
77           You can not use the ":MakeMethod" attribute with lexical or anony‐
78           mous subroutine declarations.
79
80       No method type provided for MakeMethod attribute.
81           You called ":MakeMethod()" without the required method-type argu‐
82           ment.
83

SEE ALSO

85       See Attribute::Handlers byÊDamian Conway.
86
87       See Class::MakeMethods for general information about this distribution.
88
89
90
91perl v5.8.8                       2004-09-06         MakeMethods::Attribute(3)
Impressum