| 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<use> this package, the method names you provide | ||||||||||||||||||||||
| 29 | as arguments cause subroutines to be generated and installed in | ||||||||||||||||||||||
| 30 | your module. | ||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | See L<Class::MakeMethods::Standard/"Calling Conventions"> 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<Class::MakeMethods::Standard/"Declaration Syntax"> and L<Class::MakeMethods::Standard/"Parameter Syntax"> for more information. | ||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | package Class::MakeMethods::Evaled; | ||||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | 1 | $VERSION = 1.000; | |||||||||||||||||||||
| 49 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 50 | 1 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 1 | ▶ | use Class::MakeMethods::Standard '-isasubclass'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 53 | 1 | ▶ | use Class::MakeMethods::Utility::TextBuilder 'text_builder'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | ######################################################################## | ||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | =head2 About Evaled Methods | ||||||||||||||||||||||
| 58 | |||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | 3 | ▶ | sub evaled_methods { | ||||||||||||||||||||
|
Subroutine
evaled_methods: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||
| 63 | 3 | my $class = shift; | |||||||||||||||||||||
| 64 | 3 | my $template = shift; | |||||||||||||||||||||
| 65 | 3 | my $package = $Class::MakeMethods::CONTEXT{TargetClass}; | |||||||||||||||||||||
| 66 | 3 | my @declarations = $class->_get_declarations( @_ ); | |||||||||||||||||||||
| 67 | 3 | my @code_chunks; | |||||||||||||||||||||
| 68 | 3 | foreach my $method ( @declarations ) { | |||||||||||||||||||||
| 69 | 4 | my $code = $template; | |||||||||||||||||||||
| 70 | 4 | $code =~ s/__(\w+?)__/$method->{lc $1}/eg; | |||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | # my $code = text_builder( $template, { | ||||||||||||||||||||||
| 73 | # '__NAME__' => $method->{name}, | ||||||||||||||||||||||
| 74 | # '__METHOD__{}' => $method, | ||||||||||||||||||||||
| 75 | # '__CONTEXT__{}' => $Class::MakeMethods::CONTEXT, | ||||||||||||||||||||||
| 76 | # } ); | ||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | 4 | push @code_chunks, $code; | |||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | 3 | my $code = join( "\n", "package $package;", @code_chunks, "1;" ); | |||||||||||||||||||||
| 81 | 0 | ▶ | eval $code; | ||||||||||||||||||||
|
Subroutine
a: called CC=2 SCAR=7.0
Subroutine
b: called CC=2 SCAR=7.0
Subroutine
c: called CC=2 SCAR=7.0
Subroutine
new: called CC=2 SCAR=7.0
Branch: 4 branches
| |||||||||||||||||||||||
| 82 | 3 | ▶ | $@ and Class::MakeMethods::_diagnostic('inst_eval_syntax', 'from eval', $@, $code); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 83 | 3 | return; | |||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | ######################################################################## | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | =head1 SEE ALSO | ||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | See L<Class::MakeMethods> for general information about this distribution. | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | For distribution, installation, support, copyright and license | ||||||||||||||||||||||
| 93 | information, see L<Class::MakeMethods::Docs::ReadMe>. | ||||||||||||||||||||||
| 94 | |||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | 1 | 1; | |||||||||||||||||||||