File Coverage

blib/lib/Patro/N4.pm
Criterion Covered Total %
statement 64 78 82.0
branch 13 24 54.1
condition 0 3 0.0
subroutine 24 29 82.7
pod n/a
total 101 134 75.3


line stmt bran cond sub pod time code
1             package Patro::N4;
2 8     11   48 use strict;
  8         16  
  8         262  
3 8     8   36 use warnings;
  8         20  
  8         285  
4              
5             # Patro::N4. Proxy class for ARRAY type references
6              
7             # we must keep this namespace very clean
8 8     8   35 use Carp ();
  8         15  
  8         225  
9              
10             use overload
11             '@{}' => sub {
12 8     8   36 no overloading;
  8         19  
  8         1298  
13 124 100   124   26238 if (${$_[0]}->{overloads}{'@{}'}) {
  124         549  
14 3         10 Patro::LeumJelly::deref_handler(@_,'@{}')
15             } else {
16 121         679 ${$_[0]}->{array}
17 121         243 }
18             },
19             'nomethod' => \&Patro::LeumJelly::overload_handler,
20 1     1   5 '${}' => sub { Patro::LeumJelly::deref_handler(@_,'${}') },
21 1     1   4 '%{}' => sub { Patro::LeumJelly::deref_handler(@_,'%{}') },
22 8     8   60 ;
  8         18  
  8         146  
23              
24             # override UNIVERSAL methods
25             foreach my $umethod (keys %UNIVERSAL::) {
26 8     8   419 no strict 'refs';
  8         16  
  8         574  
27             *{$umethod} = sub {
28 3     3   7 my $proxy = shift;
29 3 100       9 if (!CORE::ref($proxy)) {
30             package
31             UNIVERSAL;
32 1         9 return &$umethod($proxy,@_);
33             }
34 8     8   40 no overloading;
  8         17  
  8         1513  
35 2 50       7 my $context = defined(wantarray) ? 1 + wantarray : 0;
36             return Patro::LeumJelly::proxy_request( $$proxy,
37 2         20 { id => $$proxy->{id}, topic => 'METHOD', command => $umethod,
38             has_args => @_ > 0, args => [ @_ ], context => $context }, @_ );
39             };
40             }
41              
42             sub AUTOLOAD {
43 5     5   652 my $method = $Patro::N4::AUTOLOAD;
44 5         30 $method =~ s/.*:://;
45              
46 5         10 my $self = shift;
47 5         7 my $has_args = @_ > 0;
48 5         9 my $args = [ @_ ];
49              
50 5 50       15 my $context = defined(wantarray) ? 1 + wantarray : 0;
51 8     8   55 no overloading;
  8         18  
  8         788  
52             return Patro::LeumJelly::proxy_request( $$self,
53             { id => $$self->{id},
54 5         45 topic => 'METHOD',
55             command => $method,
56             has_args => $has_args,
57             args => $args,
58             context => $context,
59             _autoload => 1 }, @_ );
60             }
61              
62             sub DESTROY {
63 0     0   0 my $self = shift;
64 8     8   51 no overloading '${}';
  8         13  
  8         4330  
65 0 0       0 if ($$self->{_DESTROY}++) {
66 0         0 return;
67             }
68 0         0 my $socket = $$self->{socket};
69 0 0       0 if ($socket) {
70             my $response = Patro::LeumJelly::proxy_request(
71             $$self,
72             { id => $$self->{id},
73 0         0 topic => 'META',
74             command => 'destroy' } );
75 0 0 0     0 if (CORE::ref($response) && $response->{disconnect_ok}) {
76 0         0 close $socket;
77 0         0 delete $$self->{socket};
78             }
79             }
80             }
81              
82             ############################################################
83              
84             # tie class for array proxy object. Operations on the proxy object
85             # are forwarded to the remote server
86              
87             sub Patro::Tie::ARRAY::TIEARRAY {
88 31     31   86 my ($pkg,$proxy) = @_;
89 31         159 return bless { obj => $proxy, id => $proxy->{id} }, $pkg;
90             }
91              
92             sub Patro::Tie::ARRAY::__ {
93 249     249   397 my $tied = shift;
94 249         355 my $name = shift;
95 249         342 my $context = shift;
96 249 50       665 if (!defined($context)) {
97 0 0       0 $context = defined(wantarray) ? 1 + wantarray : 0;
98             }
99             return Patro::LeumJelly::proxy_request( $tied->{obj},
100             { topic => 'ARRAY',
101             command => $name,
102             context => $context,
103             has_args => @_ > 0,
104             args => [ @_ ],
105 249         1790 id => $tied->{id} }, @_ );
106             }
107              
108 180     180   841 sub Patro::Tie::ARRAY::FETCH { return shift->__('FETCH',1,@_) }
109 7     7   22 sub Patro::Tie::ARRAY::STORE { return shift->__('STORE',0,@_) }
110 32     32   109 sub Patro::Tie::ARRAY::FETCHSIZE { return shift->__('FETCHSIZE',1) }
111 0     0   0 sub Patro::Tie::ARRAY::STORESIZE { return shift->__('STORESIZE',1,@_) }
112 0     0   0 sub Patro::Tie::ARRAY::DELETE { return shift->__('DELETE',1,@_) }
113 0     0   0 sub Patro::Tie::ARRAY::CLEAR { return shift->__('CLEAR',0) }
114 0     0   0 sub Patro::Tie::ARRAY::EXISTS { return shift->__('EXISTS',1,@_) }
115 6     6   26 sub Patro::Tie::ARRAY::PUSH { return shift->__('PUSH',1,@_) }
116 3     3   10 sub Patro::Tie::ARRAY::POP { return shift->__('POP',1) }
117 3     3   14 sub Patro::Tie::ARRAY::SHIFT { return shift->__('SHIFT',1) }
118 2     2   7 sub Patro::Tie::ARRAY::UNSHIFT { return shift->__('UNSHIFT',1,@_) }
119             sub Patro::Tie::ARRAY::SPLICE {
120 16     16   51 my $tied = shift;
121 16 100       40 my $off = @_ ? shift : 0;
122 16 100       38 my $len = @_ ? shift : 'undef';
123 16 100       62 return $tied->__('SPLICE',wantarray ? 2:1,$off,$len,@_);
124             }
125              
126             ############################################################
127              
128             1;