line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Class::MakeMethods::Evaled - Make methods with simple string evals |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package MyObject; |
9
|
|
|
|
|
|
|
use Class::MakeMethods::Evaled::Hash ( |
10
|
|
|
|
|
|
|
new => 'new', |
11
|
|
|
|
|
|
|
scalar => [ 'foo', 'bar' ], |
12
|
|
|
|
|
|
|
array => 'my_list', |
13
|
|
|
|
|
|
|
hash => 'my_index', |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This document describes the various subclasses of Class::MakeMethods |
20
|
|
|
|
|
|
|
included under the Evaled::* namespace, and the method types each |
21
|
|
|
|
|
|
|
one provides. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
The Evaled subclasses generate methods using a simple string templating mechanism and basic string evals. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 Calling Conventions |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
When you C |
29
|
|
|
|
|
|
|
as arguments cause subroutines to be generated and installed in |
30
|
|
|
|
|
|
|
your module. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
See L for more information. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 Declaration Syntax |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
To declare methods, pass in pairs of a method-type name followed |
37
|
|
|
|
|
|
|
by one or more method names. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Valid method-type names for this package are listed in L<"METHOD |
40
|
|
|
|
|
|
|
GENERATOR TYPES">. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
See L and L for more information. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
package Class::MakeMethods::Evaled; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$VERSION = 1.000; |
49
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
50
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
83
|
|
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
1
|
|
843
|
use Class::MakeMethods::Standard '-isasubclass'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
53
|
1
|
|
|
1
|
|
589
|
use Class::MakeMethods::Utility::TextBuilder 'text_builder'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
######################################################################## |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 About Evaled Methods |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub evaled_methods { |
63
|
3
|
|
|
3
|
0
|
6
|
my $class = shift; |
64
|
3
|
|
|
|
|
6
|
my $template = shift; |
65
|
3
|
|
|
|
|
5
|
my $package = $Class::MakeMethods::CONTEXT{TargetClass}; |
66
|
3
|
|
|
|
|
15
|
my @declarations = $class->_get_declarations( @_ ); |
67
|
3
|
|
|
|
|
4
|
my @code_chunks; |
68
|
3
|
|
|
|
|
5
|
foreach my $method ( @declarations ) { |
69
|
4
|
|
|
|
|
5
|
my $code = $template; |
70
|
4
|
|
|
|
|
21
|
$code =~ s/__(\w+?)__/$method->{lc $1}/eg; |
|
10
|
|
|
|
|
53
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# my $code = text_builder( $template, { |
73
|
|
|
|
|
|
|
# '__NAME__' => $method->{name}, |
74
|
|
|
|
|
|
|
# '__METHOD__{}' => $method, |
75
|
|
|
|
|
|
|
# '__CONTEXT__{}' => $Class::MakeMethods::CONTEXT, |
76
|
|
|
|
|
|
|
# } ); |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
16
|
push @code_chunks, $code; |
79
|
|
|
|
|
|
|
} |
80
|
3
|
|
|
|
|
16
|
my $code = join( "\n", "package $package;", @code_chunks, "1;" ); |
81
|
3
|
100
|
|
9
|
|
405
|
eval $code; |
|
9
|
50
|
|
5
|
|
21
|
|
|
9
|
50
|
|
1
|
|
24
|
|
|
2
|
100
|
|
4
|
|
13
|
|
|
7
|
|
|
|
|
31
|
|
|
5
|
|
|
|
|
330
|
|
|
5
|
|
|
|
|
17
|
|
|
0
|
|
|
|
|
0
|
|
|
5
|
|
|
|
|
26
|
|
|
1
|
|
|
|
|
34
|
|
|
1
|
|
|
|
|
6
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1186
|
|
|
4
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
59
|
|
|
3
|
|
|
|
|
25
|
|
82
|
3
|
50
|
|
|
|
9
|
$@ and Class::MakeMethods::_diagnostic('inst_eval_syntax', 'from eval', $@, $code); |
83
|
3
|
|
|
|
|
17
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
######################################################################## |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SEE ALSO |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
See L for general information about this distribution. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
For distribution, installation, support, copyright and license |
93
|
|
|
|
|
|
|
information, see L. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |