| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 43 | 6 | ▶ | if (exists ${$interface_methods}{$method_name}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||