| 1 | package Kelp::Base; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 58 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 58 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 58 | ▶ | use feature (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 58 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 58 | require namespace::autoclean; | |||||||||||||||||||||||||||
| 9 | 58 | require Kelp::Util; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub import | ||||||||||||||||||||||||||||
| 12 | 923 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 13 | 923 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 923 | my $caller = caller; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # Do not import into inherited classes | ||||||||||||||||||||||||||||
| 17 | 923 | ▶ | return if $class ne __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 746 | ▶ | my $base = shift || $class; | ||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $class
MC/DC0%0/2
shift() || $class
shift()
$class
Truth table66%2/3
A || B
A= shift()B= $class
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 746 | ▶ | if ($base ne '-strict') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 58 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 58 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 659 | ▶ | if ($base ne '-attr') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 658 | Kelp::Util::load_package($base); | |||||||||||||||||||||||||||
| 27 | 658 | push @{"${caller}::ISA"}, $base; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 659 | ▶ | *{"${caller}::attr"} = sub { attr($caller, @_) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 659 | namespace::autoclean->import( | |||||||||||||||||||||||||||
| 33 | -cleanee => $caller | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 746 | strict->import; | |||||||||||||||||||||||||||
| 38 | 746 | warnings->import; | |||||||||||||||||||||||||||
| 39 | 746 | feature->import(':5.10'); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub new | ||||||||||||||||||||||||||||
| 43 | 1304 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 1304 | my $self = shift; | |||||||||||||||||||||||||||
| 45 | 1304 | return bless {@_}, $self; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub attr | ||||||||||||||||||||||||||||
| 49 | 2843 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
attr: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 2843 | my ($class, $name, $default) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2843 | ▶ | if (ref $default && ref $default ne 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $default and ref $default ne "CODE"
MC/DC0%0/2
ref $default and ref $default ne "CODE"
ref $default
ref $default ne "CODE"
Truth table66%2/3
A and B
A= ref $defaultB= ref $default ne "CODE"
| |||||||||||||||||||||||||||||
| 53 | 0 | croak "Default value for '$name' can not be a reference."; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Readonly attributes are marked with '-' | ||||||||||||||||||||||||||||
| 57 | 2843 | my $readonly = $name =~ s/^\-//; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # Remember if default is a function | ||||||||||||||||||||||||||||
| 60 | 2843 | my $default_sub = ref $default eq 'CODE'; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 58 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | 58 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2843 | ▶ | *{"${class}::$name"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 67 | 31666 | ▶ | return $_[0]->{$name} = $_[1] if @_ > 1 && !$readonly; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ > 1 and not $readonly
MC/DC100%2/2
@_ > 1 and not $readonly
@_ > 1
not $readonly
Truth table100%3/3
A and not(B)
A= @_ > 1B= not $readonly
| |||||||||||||||||||||||||||||
| 68 | 27650 | ▶ | return $_[0]->{$name} if exists $_[0]->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 3376 | ▶ | return $_[0]->{$name} = $default_sub ? $default->($_[0]) : $default; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 2843 | }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 58 | 1; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||