| 1 | package EO; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 18 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 18 | ▶ | use EO::Error; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 18 | ▶ | use Data::UUID; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 18 | ▶ | use EO::Attributes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 18 | ▶ | use EO::NotAttributes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 18 | ▶ | use Class::Accessor::Chained; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 18 | ▶ | use Data::Structure::Util qw( get_blessed ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 18 | ▶ | use Storable; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 18 | ▶ | use base qw( Class::Accessor::Chained ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 18 | our $VERSION = 0.96; | |||||||||||||||||||
| 17 | 18 | our $AUTOLOAD; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 18 | exception EO::Error::New; | |||||||||||||||||||
| 20 | 18 | exception EO::Error::Method; | |||||||||||||||||||
| 21 | 18 | exception EO::Error::Method::Private extends => 'EO::Error::Method'; | |||||||||||||||||||
| 22 | 18 | exception EO::Error::Method::NotFound extends => 'EO::Error::Method'; | |||||||||||||||||||
| 23 | 18 | exception EO::Error::Method::Abstract extends => 'EO::Error::Method'; | |||||||||||||||||||
| 24 | 18 | exception EO::Error::InvalidParameters; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 222 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 27 | 222 | my $proto = shift; | |||||||||||||||||||
| 28 | 222 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 29 | 222 | my $self = bless $class->primitive(), $class; | |||||||||||||||||||
| 30 | 222 | my $text = "Couldn't create object of class '$class'"; | |||||||||||||||||||
| 31 | 222 | ▶ | throw EO::Error::New text => $text unless $self->init( @_ ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 219 | ▶ | if (!$self->{ _eo_init_success }) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 1 | require Carp; | |||||||||||||||||||
| 34 | 1 | my $class = ref($self); | |||||||||||||||||||
| 35 | 1 | Carp::cluck("init not passed up the call chain"); | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | 219 | return $self; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 220 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 41 | 220 | my $self = shift; | |||||||||||||||||||
| 42 | 220 | $self->{ _eo_init_success } = 1; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 8 | ▶ | sub generate_oid { | ||||||||||||||||||
|
Subroutine
generate_oid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 46 | 8 | Data::UUID->new()->create_str(); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 222 | ▶ | sub primitive : Private { | ||||||||||||||||||
|
Subroutine
primitive: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 50 | 222 | return { _eo_init_success => 0 }; | |||||||||||||||||||
| 51 | 18 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 8 | ▶ | sub set_oid : Private { | ||||||||||||||||||
|
Subroutine
set_oid: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 54 | 8 | my $self = shift; | |||||||||||||||||||
| 55 | 8 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 8 | $self->{ oid } = shift; | |||||||||||||||||||
| 57 | 8 | return $self; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 18 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 10 | ▶ | sub oid { | ||||||||||||||||||
|
Subroutine
oid: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 62 | 10 | my $self = shift; | |||||||||||||||||||
| 63 | 10 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | throw EO::Error::InvalidParameters text => "Can't set read-only valid oid"; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | ## generate oids lazily | ||||||||||||||||||||
| 67 | 10 | ▶ | if (!$self->{ oid }) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 4 | $self->set_oid( $self->generate_oid() ); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | 10 | return $self->{ oid }; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||||||||
| 75 | 0 | ▶ | my $class = ref($self) ? ref($self) : $self; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 0 | my $meth = substr($AUTOLOAD, rindex($AUTOLOAD, ':') + 1); | |||||||||||||||||||
| 77 | 0 | my $text = "Can't locate object method \"$meth\" via package '$class'"; | |||||||||||||||||||
| 78 | 0 | local($Error::Depth) = $Error::Depth + 1; | |||||||||||||||||||
| 79 | 0 | throw EO::Error::Method::NotFound text => $text; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 2 | ▶ | sub clone { | ||||||||||||||||||
|
Subroutine
clone: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 83 | 2 | my $self = shift; | |||||||||||||||||||
| 84 | 2 | my $clone = Storable::dclone( $self ); | |||||||||||||||||||
| 85 | 2 | my $objs = get_blessed( $clone ); | |||||||||||||||||||
| 86 | ## ensure we regenerate the oids. | ||||||||||||||||||||
| 87 | 2 | foreach my $object (@$objs) { | |||||||||||||||||||
| 88 | 4 | ▶ | if ($object->isa('EO')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 4 | $object->set_oid( $object->generate_oid() ); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | 2 | $clone; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | ▶ | sub as_string { | ||||||||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 96 | 0 | my $self = shift; | |||||||||||||||||||
| 97 | 0 | my $class = ref($self); | |||||||||||||||||||
| 98 | 0 | return "I am an '$class' object"; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 214 | ▶ | sub DESTROY { 1; } | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 18 | 1; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||