| 1 | package Class::AccessorMaker::Private; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | ## | ||||||||||||||||||||||||||||
| 4 | ## Class::AccessorMaker::Private by Hartog 'Sinister' de Mik | ||||||||||||||||||||||||||||
| 5 | ## | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = "1.0"; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # lexical for data-hiding | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | my %obj_ = (); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=10 SCAR=26.6
| |||||||||||||||||||||||||||||
| 19 | 3 | my ($class, $subs, $xtra) = @_; | |||||||||||||||||||||||||||
| 20 | 3 | ▶ | my $pkg = ref(caller) || caller; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref caller || caller
MC/DC0%0/2
ref caller || caller
ref caller
caller
Truth table33%1/3
A || B
A= ref callerB= caller
| |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | $xtra ||=""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$xtra ||= ""
MC/DC100%1/1
$xtra ||= ""
$xtra
Truth table100%2/2
A
A= $xtra
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | croak "Can't make methods out of an empty hash-ref\n" if !defined $subs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ## define a constructor | ||||||||||||||||||||||||||||
| 26 | 3 | ▶ | if ( $xtra ne "no_new" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | # we have a green light for 'new()' creation | ||||||||||||||||||||||||||||
| 28 | 2 | ▶ | if ( $xtra ne "new_init" ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | *{"${pkg}::new"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=23.1
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $class = ref($_[0]) || $_[0]; shift; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||
| 31 | 0 | my $self = bless({}, $class); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | my ($sub, $value) = (shift, shift); | |||||||||||||||||||||||||||
| 35 | 0 | $self->$sub($value); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | return $self; | |||||||||||||||||||||||||||
| 39 | 1 | }; | |||||||||||||||||||||||||||
| 40 | } elsif ( $xtra eq "new_init" ) { | ||||||||||||||||||||||||||||
| 41 | 1 | ▶ | *{"${pkg}::new"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | my $class = ref($_[0]) || $_[0]; shift; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||
| 43 | 1 | my $self = bless({}, $class); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | my ($sub, $value) = (shift, shift); | |||||||||||||||||||||||||||
| 47 | 0 | $self->$sub($value); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | $self->init(); | |||||||||||||||||||||||||||
| 51 | 1 | return $self; | |||||||||||||||||||||||||||
| 52 | 1 | }; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 3 | foreach my $sub ( keys %$subs ) { | |||||||||||||||||||||||||||
| 58 | # construct the method if it is not defined yet. | ||||||||||||||||||||||||||||
| 59 | 6 | ▶ | next if ( defined &{"${pkg}::$sub"} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 6 | ▶ | *{"${pkg}::$sub"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||
| 62 | 4 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # fill with default at first run | ||||||||||||||||||||||||||||
| 65 | 4 | ▶ | $obj_{$self}->{$sub} = $subs->{$sub} if !exists $obj_{$self}->{$sub}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # more then just self, something has to be set. | ||||||||||||||||||||||||||||
| 68 | 4 | ▶ | if ($#_ > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | warn "The value supplied to '$sub()' is not of propper type" | ||||||||||||||||||||||||||||
| 70 | 1 | ▶ | if (ref($subs->{$sub}) and !ref($value)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $subs->{$sub} and not ref $value
MC/DC0%0/2
ref $subs->{$sub} and not ref $value
ref $subs->{$sub}
not ref $value
Truth table33%1/3
A and not(B)
A= ref $subs->{$sub}B= not ref $value
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # set the value and return the object. | ||||||||||||||||||||||||||||
| 73 | 1 | $obj_{$self}->{$sub} = $value; | |||||||||||||||||||||||||||
| 74 | 1 | return $self; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # return the value; | ||||||||||||||||||||||||||||
| 78 | 3 | return $obj_{$self}->{$sub}; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 6 | ▶ | } or warn "Method: $sub not implemented\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 3 | return 1; # import succeeded | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 3 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||