« blib/lib/Class/MakeMethods/Template/Array.pm
↑ Summary
blib/lib/Class/MakeMethods/Standard/Hash.pm »
| 1 | package Class::MakeMethods::Autoload; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Class::MakeMethods; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Class::MakeMethods::Utility::Inheritable 'get_vvalue'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use vars qw( $VERSION @ISA @EXPORT_OK ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | $VERSION = 1.000; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | @EXPORT_OK = qw( AUTOLOAD ); | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use vars qw( $AUTOLOAD %DefaultType ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | my $target_class = ( caller(0) )[0]; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | if ( scalar @_ and $_[0] =~ m/^\d/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @_ and $_[0] =~ /^\d/
MC/DC0%0/2
scalar @_ and $_[0] =~ /^\d/
scalar @_
$_[0] =~ /^\d/
Truth table33%1/3
A and B
A= scalar @_B= $_[0] =~ /^\d/
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | Class::MakeMethods::_import_version( $class, shift ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | if ( scalar @_ == 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | $DefaultType{ $target_class } = shift; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | __PACKAGE__->Exporter::export_to_level(1, $class, 'AUTOLOAD'); | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=11 SCAR=27.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | my $sym = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 6 | my ($package, $func) = ($sym =~ /(.*)::([^:]+)$/); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | unless ( $DefaultType{$package} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | local $_ = get_vvalue( \%DefaultType, $package ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | $DefaultType{$package} = $_ if ( $_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | ▶ | my $type = $DefaultType{$package} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | or croak(__PACKAGE__ . ": No default method type for $package; can't auto-generate $func"); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | if ( ref $type eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | my $n_type = $type->{ $func } || | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | ( map $type->{$_}, grep { $func =~ m/\A$_\Z/ } sort { length($b) <=> length($a) } keys %$type )[0] || | |||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | $type->{ '' } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$type->{$func} || (map $type->{$_}, grep({$func =~ /\A$_\Z/;} (sort {length $b <=> length $a;} keys %$type)))[0] || $type->{''}
$type->{$func} or (map $type->{$_}, grep({$func =~ /\A$_\Z/;} (sort {length $b <=> length $a;} keys %$type)))[0]
MC/DC0%0/3
$type->{$func} || (map $type->{$_}, grep({$func =~ /\A$_\Z/;} (sort {length $b <=> length $a;} keys %$type)))[0] || $type->{''}
$type->{$func}
(map $type->{$_}, grep({$func =~ /\A$_\Z/;} (sort {length $b <=> length $a;} keys %$type)))[0]
$type->{''}
Truth table50%2/4
A or B || C
A= $type->{$func}B= (map $type->{$_}, grep({$func =~ /\A$_\Z/;} (sort {length $b <=> length $a;} keys %$type)))[0]C= $type->{''}
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | or croak(__PACKAGE__ . ": Can't find best match for '$func' in type map (" . join(', ', keys %$type ) . ")"); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | $type = $n_type; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } elsif ( ref $type eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $type = &$type( $func ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | or croak(__PACKAGE__ . ": Can't find match for '$func' in type map ($type)"); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # warn "Autoload $func ($type)"; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | Class::MakeMethods->make( | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | -TargetClass => $package, | |||||||||||||||||||||||||||||||||||||||||
| 61 | -ForceInstall => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | $type => $func | ||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | ▶ | if ( my $sub = $package->can( $func ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | goto &$sub; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | croak(__PACKAGE__ . ": Construction of $type method ${package}::$func failed to produce usable method") | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||||||||||||