« blib/lib/Class/MakeMethods/Template.pm
↑ Summary
blib/lib/Class/MakeMethods/Template/StructBuiltin.pm »
| 1 | ### Class::MakeMethods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright 2002, 2003 Matthew Simon Cavalletto | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # See documentation, license, and other information after _END_. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | package Class::MakeMethods; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 90 | require 5.00307; # for the UNIVERSAL::isa method. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 90 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 90 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 90 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 90 | $VERSION = 1.010; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 90 | ▶ | use vars qw( %CONTEXT %DIAGNOSTICS ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ### MODULE IMPORT: import(), _import_version() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 452 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 452 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 452 | ▶ | if ( scalar @_ and $_[0] =~ m/^\d/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @_ and $_[0] =~ /^\d/
MC/DC0%0/2
scalar @_ and $_[0] =~ /^\d/
scalar @_
$_[0] =~ /^\d/
Truth table66%2/3
A and B
A= scalar @_B= $_[0] =~ /^\d/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | $class->_import_version( shift ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 452 | ▶ | if ( scalar @_ == 1 and $_[0] eq '-isasubclass' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @_ == 1 and $_[0] eq "-isasubclass"
MC/DC50%1/2
scalar @_ == 1 and $_[0] eq "-isasubclass"
scalar @_ == 1
$_[0] eq "-isasubclass"
Truth table66%2/3
A and B
A= scalar @_ == 1B= $_[0] eq "-isasubclass"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 329 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 329 | my $target_class = ( caller )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 90 | ▶ | no strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 329 | push @{"$target_class\::ISA"}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 452 | ▶ | $class->make( @_ ) if ( scalar @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub _import_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_import_version: not called CC=5 SCAR=30.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $wanted = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 90 | ▶ | no strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $version = ${ $class.'::VERSION '}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # If passed a version number, ensure that we measure up. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Based on similar functionality in Exporter.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( ! $version or $version < $wanted ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $version or $version < $wanted
MC/DC0%0/2
not $version or $version < $wanted
not $version
$version < $wanted
Truth table0%0/3
not(A) or B
A= not $versionB= $version < $wanted
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $file = "$class.pm"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $file =~ s!::!/!g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $file = $INC{$file} ? " ($INC{$file})" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | _diagnostic('mm_version_fail', $class, $wanted, $version || '(undef)', $file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$version || '(undef)'
MC/DC0%0/1
$version || '(undef)'
$version
Truth table0%0/2
A
A= $version
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ### METHOD GENERATION: make() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 159 | ▶ | sub make { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make: called CC=24 SCAR=32.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 159 | local $CONTEXT{MakerClass} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # Find the first class in the caller() stack that's not a subclass of us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 159 | local $CONTEXT{TargetClass}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 159 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 298 | $CONTEXT{TargetClass} = ( caller($i ++) )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 159 | ▶ | } while UNIVERSAL::isa($CONTEXT{TargetClass}, __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 159 | my @methods; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # For compatibility with 5.004, which fails to splice use's constant @_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 159 | my @declarations = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if (@_ % 2) { _diagnostic('make_odd_args', $CONTEXT{MakerClass}); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 159 | ▶ | while ( scalar @declarations ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # The list passed to import should alternate between the names of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # meta-method to call to generate the methods, and arguments to it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 335 | my ($name, $args) = splice(@declarations, 0, 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 335 | ▶ | unless ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | croak "Undefined name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Leading dash on the first argument of a pair means it's a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # global/general option to be stored in CONTEXT. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 335 | ▶ | if ( $name =~ s/^\-// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # To prevent difficult-to-predict retroactive behaviour, start by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # flushing any pending methods before letting settings take effect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 46 | ▶ | if ( scalar @methods ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | _install_methods( $CONTEXT{MakerClass}, @methods ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | @methods = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 46 | ▶ | if ( $name eq 'MakerClass' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # Switch base package for remainder of args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 15 | $CONTEXT{MakerClass} = _find_subclass($CONTEXT{MakerClass}, $args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 31 | $CONTEXT{$name} = $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 46 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # Argument normalization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 289 | ▶ | my @args = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ! ref($args) ? split(' ', $args) : # If a string, it is split on spaces. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ref($args) eq 'ARRAY' ? (@$args) : # If an arrayref, use its contents. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ( $args ) # If a hashref, it is used directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # If the type argument contains an array of method types, do the first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # now, and put the others back in the queue to be processed subsequently. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 289 | ▶ | if ( ref($name) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | ($name, my @name) = @$name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | unshift @declarations, map { $_=>[@args] } @name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # If the type argument contains space characters, use the first word | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # as the type, and prepend the remaining items to the argument list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 289 | ▶ | if ( $name =~ /\s/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 52 | my @items = split ' ', $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 52 | $name = shift( @items ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 52 | unshift @args, @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # If name contains a colon or double colon, treat the preceeding part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # as the subclass name but only for this one set of methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 289 | ▶ | local $CONTEXT{MakerClass} = _find_subclass($CONTEXT{MakerClass}, $1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | if ($name =~ s/^(.*?)\:{1,2}(\w+)$/$2/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Meta-method invocation via named_method or direct method call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | my @results = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | $CONTEXT{MakerClass}->can('named_method') ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | $CONTEXT{MakerClass}->named_method( $name, @args ) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | $CONTEXT{MakerClass}->can($name) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 289 | ▶ | $CONTEXT{MakerClass}->$name( @args ) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | croak "Can't generate $CONTEXT{MakerClass}->$name() methods" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # warn "$CONTEXT{MakerClass} $name - ", join(', ', @results) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ### A method-generator may be implemented in any of the following ways: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # SELF-CONTAINED: It may return nothing, if there are no methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # to install, or if it has installed the methods itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # (We also accept a single false value, for backward compatibility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # with generators that are written as foreach loops, which return ''!) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 289 | ▶ | if ( ! scalar @results or scalar @results == 1 and ! $results[0] ) { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition66%4/6
not scalar @results or scalar @results == 1 and not $results[0]
scalar @results == 1 and not $results[0]
MC/DC33%1/3
not scalar @results or scalar @results == 1 and not $results[0]
not scalar @results
scalar @results == 1
not $results[0]
Truth table75%3/4
not(A) or B and not(C)
A= not scalar @resultsB= scalar @results == 1C= not $results[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # ALIAS: It may return a string containing a meta-method type to run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # instead. Put the arguments back in the queue and go through again. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ▶ | elsif ( scalar @results == 1 and ! ref $results[0]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
scalar @results == 1 and not ref $results[0]
MC/DC100%2/2
scalar @results == 1 and not ref $results[0]
scalar @results == 1
not ref $results[0]
Truth table100%3/3
A and not(B)
A= scalar @results == 1B= not ref $results[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 17 | unshift @declarations, $results[0], \@args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # REWRITER: It may return one or more array reference containing a meta- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # method type and arguments which should be created to complete this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # request. Put the arguments back in the queue and go through again. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 429 | elsif ( ! grep { ref $_ ne 'ARRAY' } @results ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 13 | unshift @declarations, ( map { shift(@$_), $_ } @results ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # CODE REFS: It may provide a list of name, code pairs to install | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ▶ | elsif ( ! scalar @results % 2 and ! ref $results[0] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
scalar @results % 2 || ref $results[0]
MC/DC50%1/2
scalar @results % 2 || ref $results[0]
scalar @results % 2
ref $results[0]
Truth table66%2/3
A || B
A= scalar @results % 2B= ref $results[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 95 | push @methods, @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # GENERATOR OBJECT: It may return an object reference which will construct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # the relevant methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | elsif ( UNIVERSAL::can( $results[0], 'make_methods' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 161 | push @methods, ( shift @results )->make_methods(@results, @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | _diagnostic('make_bad_meta', $name, join(', ', map "'$_'", @results)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 159 | _install_methods( $CONTEXT{MakerClass}, @methods ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 159 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ### DECLARATION PARSING: _get_declarations() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 89 | ▶ | sub _get_declarations { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_declarations: called CC=18 SCAR=44.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 89 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 89 | my @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | my %defaults; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 89 | ▶ | while (scalar @_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 118 | my $m_name = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 118 | ▶ | if ( ! defined $m_name or ! length $m_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition33%1/3
defined $m_name && length $m_name
MC/DC0%0/2
defined $m_name && length $m_name
defined $m_name
length $m_name
Truth table33%1/3
A && B
A= defined $m_nameB= length $m_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | _diagnostic('make_empty') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Various forms of default parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | elsif ( substr($m_name, 0, 1) eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ( substr($m_name, 1, 1) ne '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # Parse default values in the format "-param => value" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $defaults{ substr($m_name, 1) } = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } elsif ( length($m_name) == 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Parse hash of default values in the format "-- => { ... }" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | ref($_[0]) eq 'HASH' or _diagnostic('make_unsupported', $m_name.$_[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | %defaults = ( %defaults, %{ shift @_ } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Parse "special" arguments in the format "--foobar" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $defaults{ '--' } .= $m_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # Parse string and string-then-hash declarations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | elsif ( ! ref $m_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 96 | ▶ | if ( scalar @_ and ref $_[0] eq 'HASH' and ! exists $_[0]->{'name'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
scalar @_ and ref $_[0] eq "HASH" and not exists $_[0]{"name"}
scalar @_ and ref $_[0] eq "HASH"
MC/DC66%2/3
scalar @_ and ref $_[0] eq "HASH" and not exists $_[0]{"name"}
scalar @_
ref $_[0] eq "HASH"
not exists $_[0]{"name"}
Truth table75%3/4
A and B and not(C)
A= scalar @_B= ref $_[0] eq "HASH"C= not exists $_[0]{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 24 | push @results, { %defaults, 'name' => $m_name, %{ shift @_ } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 72 | push @results, { %defaults, 'name' => $m_name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Parse hash-only declarations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | elsif ( ref $m_name eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 22 | ▶ | if ( length $m_name->{'name'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 22 | push @results, { %defaults, %$m_name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | _diagnostic('make_noname'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # Normalize: If we've got an array of names, replace it with those names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | elsif ( ref $m_name eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my @items = @{ $m_name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # If array is followed by an params hash, each one gets the same params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ( scalar @_ and ref $_[0] eq 'HASH' and ! exists $_[0]->{'name'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
scalar @_ and ref $_[0] eq "HASH" and not exists $_[0]{"name"}
scalar @_ and ref $_[0] eq "HASH"
MC/DC0%0/3
scalar @_ and ref $_[0] eq "HASH" and not exists $_[0]{"name"}
scalar @_
ref $_[0] eq "HASH"
not exists $_[0]{"name"}
Truth table0%0/4
A and B and not(C)
A= scalar @_B= ref $_[0] eq "HASH"C= not exists $_[0]{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $params = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | @items = map { $_, $params } @items | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | unshift @_, @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | _diagnostic('make_unsupported', $m_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 89 | return @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | ### FUNCTION INSTALLATION: _install_methods() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 159 | ▶ | sub _install_methods { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install_methods: called CC=9 SCAR=25.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 159 | my ($class, %methods) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 90 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # print STDERR "CLASS: $class\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 159 | my $package = $CONTEXT{TargetClass}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 159 | my ($name, $code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 159 | ▶ | while (($name, $code) = each %methods) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Skip this if the target package already has a function by the given name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | next if ( ! $CONTEXT{ForceInstall} and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 729 | ▶ | defined *{$package. '::'. $name}{CODE} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $Class::MakeMethods::CONTEXT{"ForceInstall"} and defined *{$package . '::' . $name;}{"CODE"}
MC/DC100%2/2
not $Class::MakeMethods::CONTEXT{"ForceInstall"} and defined *{$package . '::' . $name;}{"CODE"}
not $Class::MakeMethods::CONTEXT{"ForceInstall"}
defined *{$package . '::' . $name;}{"CODE"}
Truth table100%3/3
not(A) and B
A= not $Class::MakeMethods::CONTEXT{"ForceInstall"}B= defined *{$package . '::' . $name;}{"CODE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 724 | ▶ | if ( ! ref $code ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | local $^W; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $coderef = eval $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | _diagnostic('inst_eval_syntax', $name, $@, $code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } elsif ( ref $coderef ne 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | _diagnostic('inst_eval_result', $name, $coderef, $code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $code = $coderef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } elsif ( ref $code ne 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | _diagnostic('inst_result', $name, $code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Add the code refence to the target package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # _diagnostic('debug_install', $package, $name, $code); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 724 | ▶ | local $^W = 0 if ( $CONTEXT{ForceInstall} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 724 | *{$package . '::' . $name} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 159 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ### SUBCLASS LOADING: _find_subclass() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # $pckg = _find_subclass( $class, $optional_package_name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 3728 | ▶ | sub _find_subclass { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_subclass: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 3728 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 3728 | ▶ | my $package = shift or die "No package for _find_subclass"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 3728 | ▶ | $package = $package =~ s/^::// ? $package : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | "Class::MakeMethods::$package"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 3728 | (my $file = $package . '.pm' ) =~ s|::|/|go; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 3728 | ▶ | return $package if ( $::INC{ $file } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 90 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 93 | ▶ | return $package if ( @{$package . '::ISA'} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 92 | local $SIG{__DIE__} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 92 | eval { require $file }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 92 | $::INC{ $package } = $::INC{ $file }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if ( $@ ) { _diagnostic('mm_package_fail', $package, $@) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 92 | return $package | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | ### CONTEXT: _context(), %CONTEXT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 171 | ▶ | sub _context { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_context: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 171 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 171 | ▶ | return %CONTEXT if ( ! scalar @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 171 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 171 | ▶ | return $CONTEXT{$key} if ( ! scalar @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $CONTEXT{$key} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 90 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 90 | ▶ | $CONTEXT{Debug} ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Class::MakeMethods::CONTEXT{"Debug"} ||= 0
MC/DC0%0/1
$Class::MakeMethods::CONTEXT{"Debug"} ||= 0
$Class::MakeMethods::CONTEXT{"Debug"}
Truth table50%1/2
A
A= $Class::MakeMethods::CONTEXT{"Debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ### DIAGNOSTICS: _diagnostic(), %DIAGNOSTICS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1125 | ▶ | sub _diagnostic { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_diagnostic: called CC=7 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1125 | my $case = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1125 | my $message = $DIAGNOSTICS{$case}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1125 | $message =~ s/\A\s*\((\w)\)\s*//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1125 | ▶ | my $severity = $1 || 'I'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$1 || 'I'
MC/DC0%0/1
$1 || 'I'
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1125 | ▶ | if ( $severity eq 'Q' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 1125 | ▶ | carp( sprintf( $message, @_ ) ) if ( $CONTEXT{Debug} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } elsif ( $severity eq 'W' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | carp( sprintf( $message, @_ ) ) if ( $^W ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } elsif ( $severity eq 'F' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | croak( sprintf( $message, @_ ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | confess( sprintf( $message, @_ ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 90 | ▶ | BEGIN { %DIAGNOSTICS = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | ### BASE CLASS DIAGNOSTICS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # _diagnostic('debug_install', $package, $name, $code) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | debug_install => q|(W) Installing function %s::%s (%s)|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # _diagnostic('make_odd_args', $CONTEXT{MakerClass}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | make_odd_args => q|(F) Odd number of arguments passed to %s method generator|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # _diagnostic('make_bad_meta', $name, join(', ', map "'$_'", @results) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | make_bad_meta => q|(I) Unexpected return value from method constructor %s: %s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | # _diagnostic('inst_eval_syntax', $name, $@, $code) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | inst_eval_syntax => q|(I) Unable to compile generated method %s(): %s| . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | qq|\n (There's probably a syntax error in this generated code.)\n%s\n|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # _diagnostic('inst_eval_result', $name, $coderef, $code) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | inst_eval_result => q|(I) Unexpected return value from compilation of %s(): '%s'| . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | qq|\n (This generated code should have returned a code ref.)\n%s\n|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # _diagnostic('inst_result', $name, $code) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | inst_result => q|(I) Unable to install code for %s() method: '%s'|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # _diagnostic('mm_package_fail', $package, $@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | mm_package_fail => q|(F) Unable to dynamically load %s: %s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # _diagnostic('mm_version_fail', $class, $wanted, $version || '(undef) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | mm_version_fail => q|(F) %s %s required--this is only version %s%s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | ### STANDARD SUBCLASS DIAGNOSTICS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # _diagnostic('make_empty') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | make_empty => q|(F) Can't parse meta-method declaration: argument is empty or undefined|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # _diagnostic('make_noname') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | make_noname => q|(F) Can't parse meta-method declaration: missing name attribute.| . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | qq|\n (Perhaps a trailing attributes hash has become separated from its name?)|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # _diagnostic('make_unsupported', $m_name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | make_unsupported => q|(F) Can't parse meta-method declaration: unsupported declaration type '%s'|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | ### TEMPLATE SUBCLASS DIAGNOSTICS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # ToDo: Should be moved to the Class::MakeMethods::Template package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | debug_declaration => q|(Q) Meta-method declaration parsed: %s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | debug_make_behave => q|(Q) Building meta-method behavior %s: %s(%s)|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | mmdef_not_interpretable => qq|(I) Not an interpretable meta-method: '%s'| . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | qq|\n (Perhaps a meta-method attempted to import from a non-templated meta-method?)|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | make_bad_modifier => q|(F) Can't parse meta-method declaration: unknown option for %s: %s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | make_bad_behavior => q|(F) Can't make method %s(): template specifies unknown behavior '%s'|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | behavior_mod_unknown => q|(F) Unknown modification to %s behavior: -%s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | debug_template_builder => qq|(Q) Template interpretation for %s:\n%s|. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | qq|\n---------\n%s\n---------\n|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | debug_template => q|(Q) Parsed template '%s': %s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | debug_eval_builder => q|(Q) Compiling behavior builder '%s':| . qq|\n%s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | make_behavior_mod => q|(F) Can't apply modifiers (%s) to code behavior %s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | behavior_eval => q|(I) Class::MakeMethods behavior compilation error: %s| . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | qq|\n (There's probably a syntax error in the below code.)\n%s|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | tmpl_unkown => q|(F) Can't interpret meta-method template: unknown template name '%s'|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | tmpl_empty => q|(F) Can't interpret meta-method template: argument is empty or undefined|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | tmpl_unsupported => q|(F) Can't interpret meta-method template: unsupported template type '%s'|, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 90 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||