Interface.pm

filter: Statementstmt 30.4% 14 / 46 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 4 / 10 Podpod 100% 4 / 4 totaltotal 28.9% 22 / 76 CC 10 SCAR 31.6
CC
10
Cov
23%
implementedBy
56.0
create
12.0
AUTOLOAD
6.0
CRAP 23.6
« BaseClass.pm ↑ Summary Text.pm »
1 package MRP::Interface;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use MRP::Introspection;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use vars qw($AUTOLOAD %interfaces %implementers $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 $VERSION = 1.0;
11  
12 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
13 0 my ($name) = $AUTOLOAD =~ /([^:]+)$/;
14 0 my $int = $interfaces{$name};
15 0 ▶ $int or confess "Use of undefined interface: $name";
Branch: 1 branch
BranchTrueFalseTotal
$int or confess("Use of undefined interface: $name") 0 0 0
16 0 return $int;
17 }
18  
19 0 ▶sub create {
Subroutine create: not called CC=3 SCAR=24.8
Pod documented
20 0 my $thingy = shift;
21 0 my %interface = @_;
22  
23 0 my ($name, $definition);
24 0 ▶ while (($name, $definition) = each %interface) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %interface) 0 0 0
25 0 ▶ if(exists $interfaces{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $MRP::Interface::interfaces{$name}) { } 0 0 0
26 0 confess "interface $name has already been defined\n";
27 } else {
28 0 my $description = $definition->{''}; delete $definition->{''};
29 0 $interfaces{$name} = bless {name=>$name,
30 definition=>$definition,
31 implementors=>{},
32 description=>$description,
33 }, $thingy;
34 }
35 }
36 }
37  
38 0 ▶sub implementedBy {
Subroutine implementedBy: not called CC=7 SCAR=40.3
Pod documented
39 0 my ($interface,$thingy) = (shift,shift);
40 0 ▶ if(my $package = ref($thingy)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $package = ref $thingy) { } 0 0 0
41 0 foreach (keys %{$interface->{implementors}}) {
42 0 ▶ return 1 if $thingy->isa($_);
Branch: 1 branch
BranchTrueFalseTotal
if $thingy->isa($_) 0 0 0
43 }
44 0 return;
45 } else {
46 0 ▶ return if(not $thingy);
Branch: 1 branch
BranchTrueFalseTotal
unless $thingy 0 0 0
47 0 ▶ my @errors = map { $thingy->can($_)
Branch: 1 branch
BranchTrueFalseTotal
$thingy->can($_) ? : 0 0 0
48 ? () : "$_";
49 0 } keys %{$interface->{definition}};
50 0 ▶ if(@errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@errors) 0 0 0
51 confess
52 "$thingy does not implement interface ",
53 $interface->{name},
54 ". The following ", scalar(@errors), " functions must be defined:\n ",
55 0 join("", map { $_."\n\t".$interface->{definition}->{$_}."\n" } @errors),
56 "\n";
57 }
58 0 $interface->{implementors}->{$thingy} = 1;
59 }
60 }
61  
62 0 ▶sub name {
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
63 0 my $interface = shift;
64 0 return $interface->{name};
65 }
66  
67 0 ▶sub functions {
Subroutine functions: not called CC=1 SCAR=6.9
Pod documented
68 0 my $interface = shift;
69 0 return keys %{$interface->{definition}};
70 }
71  
72 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
73  
74 1 $VERSION;
75  
76 __END__
« BaseClass.pm ↑ Summary Text.pm »