blib/lib/Class/Method/Auto.pm

filter: Statementstmt 95.7% 68 / 71 Branchbran 68.1% 15 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 89.4% 93 / 104 CC 15 SCAR 15.9
CC
15
Cov
89%
import
8.1
__ANON__
6.2
__ANON__
3.0
CRAP 4.9
↑ Summary
1 package Class::Method::Auto;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = "1.00";
7  
8 1 ▶use attributes 'get';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶sub my_croak($$) {
Subroutine my_croak: called CC=1 SCAR=0.0
Pod undocumented
11 2 my ($package, $method) = @_;
12 2 require Carp;
13 2 Carp::croak "Undefined subroutine &${package}::$method called";
14 }
15  
16 3 ▶sub import {
Subroutine import: called CC=8 SCAR=21.0
17 3 shift;
18 3 my $target = caller;
19 3 my ($regexp, $check_attributes, @methods);
20 3 for (@_) {
21 3 ▶ if (ref($_) eq 'Regexp') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'Regexp') { } 1 2 3
elsif ($_ eq '-attributes') { } 1 1 2
22 1 $regexp = $_;
23 } elsif ($_ eq '-attributes') {
24 1 $check_attributes = 1;
25 } else {
26 1 push(@methods, $_);
27 }
28 }
29 3 ▶ if (@methods) { # install for every method in @_
Branch: 1 branch
BranchTrueFalseTotal
if (@methods) { } 1 2 3
30 1 for my $method(@methods) {
31 1 ▶ my $autosub = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
32 1 my $package = caller;
33 1 unshift(@_, $package);
34 1 my @isa;
35 {
36 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 @isa = @{$package.'::ISA'};
38 }
39 1 for (@isa) {
40 1 my $sub = $_->can($method);
41 1 ▶ goto &{$sub} if defined $sub;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sub 1 0 1
42 }
43 0 my_croak($package, $method);
44 1 };
45 {
46 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶ *{"${target}::$method"} = $autosub unless defined *{"${target}::$method"}{'CODE'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined *{"${target}::$method";}{"CODE"} 1 0 1
48 }
49 }
50 } else { # install globally;
51 3 ▶ my $autoload = sub {
Subroutine __ANON__: called CC=6 SCAR=18.2
52 3 my $method = our $AUTOLOAD;
53 3 $method =~ s/.*:://;
54 3 my $package = caller;
55 3 ▶ if ($regexp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($regexp) 3 0 3
56 3 ▶ my_croak($package, $method) unless ($method =~ $regexp);
Branch: 1 branch
BranchTrueFalseTotal
unless $method =~ /$regexp/ 2 1 3
57 }
58 1 unshift(@_, $package);
59 1 my $sub = $package->can($method);
60 1 ▶ my_croak($package, $method) unless defined $sub;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sub 0 1 1
61 1 ▶ if ($check_attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check_attributes) 1 0 1
62 1 my %attr;
63 1 @attr{get($sub)} = undef;
64 1 ▶ my_croak($package, $method) unless exists $attr{'method'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attr{"method"} 0 1 1
65 }
66 1 goto &{$sub};
67 2 };
68 {
69 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
70 2 ▶ if (defined *{"${target}::AUTOLOAD"}{'CODE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${target}::AUTOLOAD";}{'CODE'}) { } 0 2 2
71 0 require Carp;
72 0 Carp::croak "There already seems to be a routine named AUTOLOAD in $target";
73 } else {
74 2 *{"${target}::AUTOLOAD"} = $autoload;
75 }
76 }
77 }
78 }
79  
80  
81 1 1;
82 __END__
↑ Summary