blib/lib/Class/MakeMethods/Autoload.pm

filter: Statementstmt 93.4% 43 / 46 Branchbran 55.0% 11 / 20 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 75.0% 66 / 88 CC 14 SCAR 21.9
CC
14
Cov
77%
AUTOLOAD
14.8
import
4.7
BEGIN
1.0
CRAP 8.9
« 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
BranchTrueFalseTotal
if (scalar @_ and $_[0] =~ /^\d/) 0 2 2
Condition33%1/3
scalar @_ and $_[0] =~ /^\d/
!ll&&!rl&&r
020
MC/DC0%0/2
scalar @_ and $_[0] =~ /^\d/
scalar @_ $_[0] =~ /^\d/
Truth table33%1/3
A and B
A= scalar @_B= $_[0] =~ /^\d/
ABresult
0X0
100
111
25 0 Class::MakeMethods::_import_version( $class, shift );
26 }
27
28 2 ▶ if ( scalar @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) 2 0 2
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
BranchTrueFalseTotal
unless ($Class::MakeMethods::Autoload::DefaultType{$package}) 1 5 6
40 1 local $_ = get_vvalue( \%DefaultType, $package );
41 1 ▶ $DefaultType{$package} = $_ if ( $_ );
Branch: 1 branch
BranchTrueFalseTotal
if $_ 1 0 1
42 }
43
44 6 ▶ my $type = $DefaultType{$package}
Branch: 1 branch
BranchTrueFalseTotal
my $type = $Class::MakeMethods::Autoload::DefaultType{$package} or croak('Class::MakeMethods::Autoload' . ": No default method type for $package; can't auto-generate $func") 6 0 6
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
BranchTrueFalseTotal
if (ref $type eq 'HASH') { } 3 3 6
elsif (ref $type eq 'CODE') { } 0 3 3
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
BranchTrueFalseTotal
my $n_type = $type->{$func} || (map $type->{$_}, grep({$func =~ /\A$_\Z/;} (sort {length $b <=> length $a;} keys %$type)))[0] || $type->{""} or croak('Class::MakeMethods::Autoload' . ": Can't find best match for '${func}' in type map (" . join(", ", keys %$type) . ')') 3 0 3
Condition50%3/6
$type->{$func} || (map $type->{$_}, grep({$func =~ /\A$_\Z/;} (sort {length $b <=> length $a;} keys %$type)))[0] || $type->{''}
l!l&&r!l&&!r
300
$type->{$func} or (map $type->{$_}, grep({$func =~ /\A$_\Z/;} (sort {length $b <=> length $a;} keys %$type)))[0]
l!l&&r!l&&!r
120
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->{''}
ABCresult
1XX1
01X1
0011
0000
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
BranchTrueFalseTotal
$type = &$type($func) or croak('Class::MakeMethods::Autoload' . ": Can't find match for '${func}' in type map ($type)") 0 0 0
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
BranchTrueFalseTotal
if (my $sub = $package->can($func)) { } 6 0 6
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__
« blib/lib/Class/MakeMethods/Template/Array.pm ↑ Summary blib/lib/Class/MakeMethods/Standard/Hash.pm »