IOC/Proxy/Interfaces.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 100% 67 / 67 CC 7 SCAR 11.0
CC
7
Cov
100%
_installMethods
6.0
_init
2.0
BEGIN
1.0
CRAP 3.0
« IOC/Container.pm ↑ Summary IOC/Proxy.pm »
1  
2 package IOC::Proxy::Interfaces;
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.02';
8  
9 3 ▶use base 'IOC::Proxy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use IOC::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶sub _init {
Subroutine _init: called CC=2 SCAR=6.9
14 4 my ($self, $config) = @_;
15 4 (exists ${$config}{interface})
16 4 ▶ || throw IOC::InsufficientArguments "You must specify an interface in the configuration";
Branch: 1 branch
BranchTrueFalseTotal
exists do { $config }->{"interface"} or "IOC::InsufficientArguments"->throw("You must specify an interface in the configuration") 3 1 4
17 3 $self->SUPER::_init($config);
18 }
19  
20 # PRIVATE METHODS
21  
22 3 ▶sub _createPackageString {
Subroutine _createPackageString: called CC=1 SCAR=0.0
23 3 my ($self, $obj_class, $proxy_package) = @_;
24 3 my $package_string = $self->SUPER::_createPackageString($obj_class, $proxy_package);
25 3 my $interface = $self->{config}->{interface};
26 3 $package_string =~ s/\@ISA \= \('$obj_class'\)/\@ISA \= \('$obj_class'\, '$interface'\)/;
27 3 return $package_string;
28 }
29  
30 3 ▶sub _installMethods {
Subroutine _installMethods: called CC=6 SCAR=17.9
31 3 my ($self, $obj_class, $proxy_package, $methods) = @_;
32
33 3 my $interface = $self->{config}->{interface};
34 3 my $interface_methods = {};
35 3 $self->_collectAllMethods($interface, $interface_methods);
36 3 ▶ (keys %{$interface_methods}) || throw IOC::OperationFailed "No methods could be found in '$interface'";
Branch: 1 branch
BranchTrueFalseTotal
keys %{$interface_methods;} or "IOC::OperationFailed"->throw("No methods could be found in '${interface}'") 2 1 3
37
38 5 (exists ${$methods}{$_})
39 2 ▶ || throw IOC::IllegalOperation "The class '$obj_class' does not conform to the interface '$interface'" foreach keys %{$interface_methods};
Branch: 1 branch
BranchTrueFalseTotal
exists do { $methods }->{$_} or "IOC::IllegalOperation"->throw("The class '${obj_class}' does not conform to the interface '${interface}'") 4 1 5
40
41 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶ while (my ($method_name, $method) = each %{$methods}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$methods;}) 6 1 7
43 6 ▶ if (exists ${$interface_methods}{$method_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $interface_methods }->{$method_name}) { } 4 2 6
44 4 ▶ *{"${proxy_package}::$method_name"} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
45 2 $self->onMethodCall($method_name, $method->{full_name}, [ @_ ]);
46 2 goto &{$method->{code}};
47 4 };
48 }
49 else {
50 2 ▶ *{"${proxy_package}::$method_name"} = sub { throw IOC::MethodNotFound };
Subroutine __ANON__: called CC=1 SCAR=0.0
51 }
52 }
53 }
54  
55 3 1;
56  
57 __END__
« IOC/Container.pm ↑ Summary IOC/Proxy.pm »