Class/Abstract.pm

filter: Statementstmt 95.6% 88 / 92 Branchbran 93.7% 15 / 16 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 91.3% 21 / 23 Podpod n/a totaltotal 86.9% 127 / 146 CC 16 SCAR 11.4
CC
16
Cov
91%
____pre_validate_opts
8.0
____OOP_PERLISH_CLASS_REQUIRED_INTERFACES
4.1
_interfaces
3.0
CRAP 3.1
« Class/Multiton.pm ↑ Summary Class/Singleton.pm »
1 #!/usr/bin/perl
2 # $Id$
3 # $Author$
4 # $HeadURL$
5 # $Date$
6 # $Revision$
7 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 {
10  
11 package OOP::Perlish::Class::Abstract;
12 7 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶ use OOP::Perlish::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶ use base qw(OOP::Perlish::Class);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶ use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 7 our $VERSION = 1.0;
20  
21 ############################################################################################
22 ## Do a sanity check for required interfaces in pre-validation
23 ############################################################################################
24 sub ____pre_validate_opts
25 14 ▶ {
Subroutine ____pre_validate_opts: called CC=8 SCAR=20.8
26 14 my ($self) = @_;
27 14 my $class = ref($self);
28  
29 14 my %required_interfaces;
30  
31 14 for my $parent_class ( $self->_all_isa() ) {
32 32 ▶ if( bless( {}, $parent_class )->can('____OOP_PERLISH_CLASS_REQUIRED_INTERFACES') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (bless({}, $parent_class)->can("____OOP_PERLISH_CLASS_REQUIRED_INTERFACES")) 18 14 32
33 18 @required_interfaces{ @{ $parent_class->____OOP_PERLISH_CLASS_REQUIRED_INTERFACES() } } = undef;
34 }
35 }
36  
37 14 my %defined_interfaces;
38  
39 14 for my $parent_class ( $self->_all_isa() ) {
40 32 ▶ next if( exists( $self->____OOP_PERLISH_CLASS_ABSTRACT_CLASSES()->{$parent_class} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->____OOP_PERLISH_CLASS_ABSTRACT_CLASSES->{$parent_class} 2 30 32
41 0 for my $name ( keys %required_interfaces ) {
42 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
43 6 ▶ $defined_interfaces{$name} = undef if( defined( *{ '::' . $class . '::' . $name }{CODE} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined *{'::' . $class . '::' . $name;}{"CODE"} 3 3 6
44 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 }
46 }
47  
48 14 ▶ if( scalar keys %required_interfaces != scalar keys %defined_interfaces ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %required_interfaces != scalar keys %defined_interfaces) 1 13 14
49 confess( 'Failed to define required interfaces: '
50 1 . join( ', ', grep { !exists( $defined_interfaces{$_} ) } keys %required_interfaces ) . 'in '
51 . $class );
52 }
53  
54 13 return $self->SUPER::____pre_validate_opts();
55 }
56  
57 ############################################################################################
58 ## set interfaces, usually called like 'BEGIN { __PACKAGE__->_interfaces(...) }' as the
59 ## first section of a derived class.
60 ############################################################################################
61 sub _interfaces(@)
62 1 ▶ {
Subroutine _interfaces: called CC=3 SCAR=11.1
63 1 my ( $self, %interfaces ) = @_;
64 1 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
65  
66 1 $self->____OOP_PERLISH_CLASS_ABSTRACT_CLASSES()->{$class} = 1;
67  
68 0 for my $name ( keys %interfaces ) {
69 3 my $type = $interfaces{$name};
70  
71 ### Symbol table manipulation; creates a method named for the $name in the package's namespace
72 ### The actual method is created via closure in ____oop_perlish_class_interface_factory();
73 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 3 *{ '::' . $class . '::' . $name } = $self->____oop_perlish_class_interface_factory( $name, $type );
75 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 }
77  
78 1 return;
79 }
80  
81 ############################################################################################
82 ## return a static reference to an array of required fields for this class; must work for
83 ## all derived classes
84 ############################################################################################
85 sub ____OOP_PERLISH_CLASS_REQUIRED_INTERFACES(@)
86 19 ▶ {
Subroutine ____OOP_PERLISH_CLASS_REQUIRED_INTERFACES: called CC=4 SCAR=14.0
87 19 my ($self) = @_;
88 19 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
0190
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
89 19 our $____OOP_PERLISH_CLASS_REQUIRED_INTERFACES;
90  
91 19 ▶ $____OOP_PERLISH_CLASS_REQUIRED_INTERFACES = {} unless( defined($____OOP_PERLISH_CLASS_REQUIRED_INTERFACES) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $OOP::Perlish::Class::Abstract::____OOP_PERLISH_CLASS_REQUIRED_INTERFACES 2 17 19
92 19 ▶ $____OOP_PERLISH_CLASS_REQUIRED_INTERFACES->{$class} = [] unless( exists( $____OOP_PERLISH_CLASS_REQUIRED_INTERFACES->{$class} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $OOP::Perlish::Class::Abstract::____OOP_PERLISH_CLASS_REQUIRED_INTERFACES->{$class} 5 14 19
93  
94 19 return $____OOP_PERLISH_CLASS_REQUIRED_INTERFACES->{$class};
95 }
96  
97 ############################################################################################
98 ## Place to store a registry of all abstract classes;
99 ############################################################################################
100 sub ____OOP_PERLISH_CLASS_ABSTRACT_CLASSES(@)
101 33 ▶ {
Subroutine ____OOP_PERLISH_CLASS_ABSTRACT_CLASSES: called CC=2 SCAR=6.9
102 33 my ($self) = @_;
103 33 our $____OOP_PERLISH_CLASS_ABSTRACT_CLASSES;
104  
105 33 ▶ $____OOP_PERLISH_CLASS_ABSTRACT_CLASSES = {} unless( defined($____OOP_PERLISH_CLASS_ABSTRACT_CLASSES) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $OOP::Perlish::Class::Abstract::____OOP_PERLISH_CLASS_ABSTRACT_CLASSES 2 31 33
106  
107 33 return $____OOP_PERLISH_CLASS_ABSTRACT_CLASSES;
108 }
109  
110 ############################################################################################
111 ## Return a subroutine for the required interfaces
112 ############################################################################################
113 sub ____oop_perlish_class_interface_impl_required
114 1 ▶ {
Subroutine ____oop_perlish_class_interface_impl_required: called CC=2 SCAR=7.1
115 1 my ( $self, $name ) = @_;
116 1 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
117  
118 1 push( @{ $class->____OOP_PERLISH_CLASS_REQUIRED_INTERFACES() }, $name );
119  
120 1 ▶ return sub { confess("Interface $name is required, but was not defined"); };
Subroutine __ANON__: called CC=1 SCAR=0.0
121 }
122  
123 ############################################################################################
124 ## Return a subroutine for the optional (false) interfaces
125 ############################################################################################
126 sub ____oop_perlish_class_interface_impl_optional
127 1 ▶ {
Subroutine ____oop_perlish_class_interface_impl_optional: called CC=1 SCAR=0.4
128 1 my ( $self, $name ) = @_;
129 0 ▶ return sub { return; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
130 }
131  
132 ############################################################################################
133 ## Return a subroutine for optional_true interfaces
134 ############################################################################################
135 sub ____oop_perlish_class_interface_impl_optional_true
136 1 ▶ {
Subroutine ____oop_perlish_class_interface_impl_optional_true: called CC=1 SCAR=0.4
137 1 my ( $self, $name ) = @_;
138 0 ▶ return sub { return 1; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
139 }
140  
141 ############################################################################################
142 ## Return a subroutine for the given type
143 ############################################################################################
144 sub ____oop_perlish_class_interface_factory
145 3 ▶ {
Subroutine ____oop_perlish_class_interface_factory: called CC=2 SCAR=7.0
146 3 my ( $self, $name, $type ) = @_;
147  
148 3 my $method = '____oop_perlish_class_interface_impl_' . lc($type);
149 3 ▶ confess('Invalid type of interface specification') unless( $self->can($method) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($method) 0 3 3
150 3 return $self->$method($name);
151 }
152 }
153 7 1;
154 __END__
« Class/Multiton.pm ↑ Summary Class/Singleton.pm »