| 1 | package Egg::Component; | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # $Id: Component.pm 337 2008-05-14 12:30:09Z lushe $ | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | 37 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 37 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 37 | ▶ | use UNIVERSAL::require; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 37 | ▶ | use Class::C3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 37 | ▶ | use Tie::Hash::Indexed; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 37 | ▶ | use Carp qw/ croak /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 37 | ▶ | use base qw/ Class::Data::Inheritable /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 37 | ▶ | use Egg::Component::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 37 | our $VERSION= '3.02'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 207 | ▶ | sub initialize { | ||||||||||||||||||||||||||
|
Subroutine
initialize: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 207 | ▶ | my $class= ref($_[0]) || $_[0]; | ||||||||||||||||||||||||||
|
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]
| |||||||||||||||||||||||||||||
| 20 | 207 | for my $method (qw/ namespace regists config /) { | |||||||||||||||||||||||||||
| 21 | 621 | ▶ | next if $class->can($method); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 274 | $class->mk_classdata($method); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 207 | ▶ | unless ($class->namespace) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 137 | $class->namespace($class); | |||||||||||||||||||||||||||
| 26 | 137 | $class->regists($class->ixhash); | |||||||||||||||||||||||||||
| 27 | ## $class->config({}) unless $class->config; | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 37 | ▶ | no strict 'refs'; ## no critic. | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 37 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 207 | ▶ | *{"${class}::___add_regists"}= sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||
| 32 | 28 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | 28 | ▶ | my $label= shift || die q{I want label name.}; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || die('I want label name.')
MC/DC0%0/1
shift() || die('I want label name.')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 34 | 28 | ▶ | my $pkg = shift || die q{I want package name.}; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || die('I want package name.')
MC/DC0%0/1
shift() || die('I want package name.')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 35 | 28 | ▶ | my $conf = shift || undef; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || undef
MC/DC0%0/1
shift() || undef
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 36 | 28 | ▶ | $self->regists->{$label}= [$pkg, ($pkg->VERSION || '0.00'), $conf]; | ||||||||||||||||||||||||||
|
Condition100%2/2
$pkg->VERSION || '0.00'
MC/DC100%1/1
$pkg->VERSION || '0.00'
$pkg->VERSION
Truth table100%2/2
A
A= $pkg->VERSION
| |||||||||||||||||||||||||||||
| 37 | 207 | }; | |||||||||||||||||||||||||||
| 38 | 207 | $class; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 28 | ▶ | sub isa_register { | ||||||||||||||||||||||||||
|
Subroutine
isa_register: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 28 | my($proto, $label, $pkg)= _get_args(@_); | |||||||||||||||||||||||||||
| 42 | 28 | ▶ | $proto= ref($proto) if ref($proto); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 37 | ▶ | no strict 'refs'; ## no critic. | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 28 | push @{"${proto}::ISA"}, $pkg; | |||||||||||||||||||||||||||
| 45 | 28 | $proto->___add_regists($label, $pkg); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub add_register { | ||||||||||||||||||||||||||
|
Subroutine
add_register: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | my($proto, $label, $pkg, $conf)= _get_args(@_); | |||||||||||||||||||||||||||
| 49 | 0 | $proto->___add_regists($label, $pkg, $conf); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 207 | ▶ | sub isa_terminator { | ||||||||||||||||||||||||||
|
Subroutine
isa_terminator: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 207 | my $proto= shift; | |||||||||||||||||||||||||||
| 53 | 207 | ▶ | $proto= ref($proto) if ref($proto); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 37 | ▶ | no strict 'refs'; ## no critic. | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 207 | my $isa= \@{"${proto}::ISA"}; | |||||||||||||||||||||||||||
| 56 | 207 | ▶ | if (my $base= shift) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 69 | my $regex= quotemeta($base); | |||||||||||||||||||||||||||
| 58 | 69 | @$isa= grep !/^$regex$/, @$isa; | |||||||||||||||||||||||||||
| 59 | 69 | push @$isa, $base; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 207 | ▶ | return $proto if ($isa->[$#{$isa}] eq 'Egg::Component::Base'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 141 | @$isa= grep !/^Egg\:+Component\:+Base/, @$isa; | |||||||||||||||||||||||||||
| 63 | 141 | push @$isa, 'Egg::Component::Base'; | |||||||||||||||||||||||||||
| 64 | 141 | $proto; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 140 | ▶ | sub ixhash { | ||||||||||||||||||||||||||
|
Subroutine
ixhash: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 140 | shift; | |||||||||||||||||||||||||||
| 68 | 140 | tie my %hash, 'Tie::Hash::Indexed'; | |||||||||||||||||||||||||||
| 69 | 140 | ▶ | %hash= @_ if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 140 | \%hash; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 28 | ▶ | sub _get_args { | ||||||||||||||||||||||||||
|
Subroutine
_get_args: called CC=12 SCAR=26.6
| |||||||||||||||||||||||||||||
| 73 | 28 | my $proto = shift; | |||||||||||||||||||||||||||
| 74 | 28 | ▶ | $proto = ref($proto) if ref($proto); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 28 | ▶ | my $load = shift || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 76 | 28 | ▶ | my $label = shift || croak q{ I want label name. }; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || croak(' I want label name. ')
MC/DC0%0/1
shift() || croak(' I want label name. ')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 77 | 28 | ▶ | my $pkg = shift || $label; | ||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $label
MC/DC0%0/2
shift() || $label
shift()
$label
Truth table66%2/3
A || B
A= shift()B= $label
| |||||||||||||||||||||||||||||
| 78 | 28 | ▶ | my $config= shift || undef; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || undef
MC/DC100%1/1
shift() || undef
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 79 | 28 | ▶ | if ($load) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 2 | ▶ | $load > 1 ? do { $pkg->use or croak "$proto - $@" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 28 | ▶ | : do { $pkg->require or croak "$proto - $@" }; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 28 | ▶ | $pkg->config($config) if ($config and $pkg->can('config')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$config and $pkg->can("config")
MC/DC0%0/2
$config and $pkg->can("config")
$config
$pkg->can("config")
Truth table66%2/3
A and B
A= $configB= $pkg->can("config")
| |||||||||||||||||||||||||||||
| 84 | 28 | ($proto, lc($label), $pkg, $config, @_); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub ___add_regists { $_[0] } | ||||||||||||||||||||||||||
|
Subroutine
___add_regists: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 37 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||