All/Base.pm

filter: Statementstmt 92.5% 50 / 54 Branchbran 68.1% 15 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 5 totaltotal 81.7% 76 / 93 CC 13 SCAR 11.0
CC
13
Cov
86%
error
6.0
__ANON__
5.0
populate
3.0
CRAP 3.0
« All/IO/FTP.pm ↑ Summary All/Format/XML.pm »
1 package Data::All::Base;
2  
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 1 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our @EXPORT = qw(new internal attribute populate error );
12  
13 1 our $VERSION = 1.0;
14  
15 sub internal;
16 1 internal 'ERROR' => [];
17  
18 0 ▶sub error {
Subroutine error: not called CC=2 SCAR=17.9
Pod undocumented
19 0 my $self = shift;
20 0 ▶ push (@{ $self->__ERROR() }, @_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
21 0 $self->__ERROR();
22 }
23  
24 sub new
25 # Bypass Spiffy's new, so we can call init()
26 9 ▶{
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
27 9 my $class = shift;
28 9 my $self = bless Symbol::gensym(), $class;
29
30 9 ▶ return ($self->can('init'))
Branch: 1 branch
BranchTrueFalseTotal
$self->can('init') ? : 9 0 9
31 ? $self->init(@_)
32 : $self;
33 }
34  
35  
36 sub attribute
37 # Creates an anonymous subroutine and places it in the caller's
38 # package (i.e. $self->name).
39 # Consider lvalue expression to allow $self->name = "newvalue".
40 # http://perl.active-venture.com/pod/perlsub.html
41 18 ▶{
Subroutine attribute: called CC=2 SCAR=6.9
Pod undocumented
42 18 my $package = caller;
43 18 my ($attribute, $default) = @_;
44 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 18 ▶ return if defined &{"${package}::$attribute"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${package}::$attribute";} 0 18 18
46 18 *{"${package}::$attribute"} =
47 156 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
48 156 my $self = shift;
49 156 ▶ unless (exists *$self->{$attribute}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists *$self->{$attribute}) 40 116 156
50 40 ▶ *$self->{$attribute} =
Branch: 2 branches
BranchTrueFalseTotal
ref $default eq 'ARRAY' ? : 2 38 40
ref $default eq 'HASH' ? : 0 38 38
51 ref($default) eq 'ARRAY' ? [] :
52 ref($default) eq 'HASH' ? {} :
53 $default;
54 }
55 156 ▶ return *$self->{$attribute} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 109 47 156
56 47 *$self->{$attribute} = shift;
57 18 };
58 }
59  
60 sub internal
61 # Used like attribute 'name' => 'val'. The difference being
62 # the internal attribute and it accessor are stored as '__name'
63 10 ▶{
Subroutine internal: called CC=2 SCAR=6.9
Pod undocumented
64 10 my $package = caller;
65 10 my ($attribute, $default) = @_;
66 10 $attribute = "__$attribute";
67 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
68 10 ▶ return if defined &{"${package}::$attribute"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${package}::$attribute";} 0 10 10
69 10 *{"${package}::$attribute"} =
70 105 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
71 105 my $self = shift;
72 105 ▶ unless (exists *$self->{$attribute}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists *$self->{$attribute}) 18 87 105
73 18 *$self->{$attribute} = $default;
74 }
75 105 ▶ return *$self->{$attribute} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 85 20 105
76 20 *$self->{$attribute} = shift;
77 10 };
78 }
79  
80  
81 sub populate
82 # populate $self->ACCESSOR with arguments in $args.
83 # This is usually called by init() after the args have been parsed.
84 10 ▶{
Subroutine populate: called CC=3 SCAR=11.1
Pod undocumented
85 10 my ($self, $args) = @_;
86  
87 10 for my $a (keys %{ $args })
88 {
89 36 ▶ warn("No attribute method for $a"), next
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($a) 0 36 36
90 unless $self->can($a);
91 #warn 9, "Running $a";
92 36 $self->$a($args->{$a});
93 }
94 }
95  
96  
97  
98  
99  
100  
101 1 1;
« All/IO/FTP.pm ↑ Summary All/Format/XML.pm »