| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | package IOC::Proxy::Interfaces; | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 2 |  |  | 2 |  | 32525 | use strict; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 71 |  | 
| 5 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 73 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.02'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 9 | use base 'IOC::Proxy'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1288 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 2 |  |  | 2 |  | 12 | use IOC::Exceptions; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 576 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub _init { | 
| 14 | 4 |  |  | 4 |  | 7 | my ($self, $config) = @_; | 
| 15 | 4 | 100 |  |  |  | 7 | (exists ${$config}{interface}) | 
|  | 4 |  |  |  |  | 28 |  | 
| 16 |  |  |  |  |  |  | || throw IOC::InsufficientArguments "You must specify an interface in the configuration"; | 
| 17 | 3 |  |  |  |  | 23 | $self->SUPER::_init($config); | 
| 18 |  |  |  |  |  |  | } | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # PRIVATE METHODS | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub _createPackageString { | 
| 23 | 3 |  |  | 3 |  | 5 | my ($self, $obj_class, $proxy_package) = @_; | 
| 24 | 3 |  |  |  |  | 17 | my $package_string = $self->SUPER::_createPackageString($obj_class, $proxy_package); | 
| 25 | 3 |  |  |  |  | 9 | my $interface = $self->{config}->{interface}; | 
| 26 | 3 |  |  |  |  | 94 | $package_string =~ s/\@ISA \= \('$obj_class'\)/\@ISA \= \('$obj_class'\, '$interface'\)/; | 
| 27 | 3 |  |  |  |  | 544 | return $package_string; | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub _installMethods { | 
| 31 | 3 |  |  | 3 |  | 5 | my ($self, $obj_class, $proxy_package, $methods) = @_; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 3 |  |  |  |  | 7 | my $interface = $self->{config}->{interface}; | 
| 34 | 3 |  |  |  |  | 7 | my $interface_methods = {}; | 
| 35 | 3 |  |  |  |  | 11 | $self->_collectAllMethods($interface, $interface_methods); | 
| 36 | 3 | 100 |  |  |  | 4 | (keys %{$interface_methods}) || throw IOC::OperationFailed "No methods could be found in '$interface'"; | 
|  | 3 |  |  |  |  | 23 |  | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 2 |  |  |  |  | 7 | (exists ${$methods}{$_}) | 
|  | 5 |  |  |  |  | 27 |  | 
| 39 | 2 |  | 66 |  |  | 4 | || throw IOC::IllegalOperation "The class '$obj_class' does not conform to the interface '$interface'"				 		foreach keys %{$interface_methods}; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 2 |  |  | 2 |  | 11 | no strict 'refs'; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 377 |  | 
| 42 | 1 |  |  |  |  | 3 | while (my ($method_name, $method) = each %{$methods}) { | 
|  | 7 |  |  |  |  | 29 |  | 
| 43 | 6 | 100 |  |  |  | 8 | if (exists ${$interface_methods}{$method_name}) { | 
|  | 6 |  |  |  |  | 14 |  | 
| 44 | 4 |  |  |  |  | 24 | *{"${proxy_package}::$method_name"} = sub { | 
| 45 | 2 |  |  | 2 |  | 2071 | $self->onMethodCall($method_name, $method->{full_name}, [ @_ ]); | 
| 46 | 2 |  |  |  |  | 4 | goto &{$method->{code}}; | 
|  | 2 |  |  |  |  | 10 |  | 
| 47 | 4 |  |  |  |  | 32 | }; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  | else { | 
| 50 | 2 |  |  | 1 |  | 8 | *{"${proxy_package}::$method_name"} = sub { throw IOC::MethodNotFound }; | 
|  | 2 |  |  |  |  | 14 |  | 
|  | 1 |  |  |  |  | 1577 |  | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | 1; | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | __END__ |