line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Connector::Wrapper |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Wrapper class to filter access to a connector by a prefix |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Written by Oliver Welter for the OpenXPKI project 2012 |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# TODO: To make this really transparent it need to be inherited |
8
|
|
|
|
|
|
|
# from Connector and implement the prefix stuff |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Connector::Wrapper; |
11
|
|
|
|
|
|
|
|
12
|
13
|
|
|
13
|
|
79
|
use strict; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
353
|
|
13
|
13
|
|
|
13
|
|
59
|
use warnings; |
|
13
|
|
|
|
|
21
|
|
|
13
|
|
|
|
|
288
|
|
14
|
13
|
|
|
13
|
|
75
|
use English; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
81
|
|
15
|
13
|
|
|
13
|
|
4000
|
use Moose; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
86
|
|
16
|
13
|
|
|
13
|
|
71604
|
use Data::Dumper; |
|
13
|
|
|
|
|
5751
|
|
|
13
|
|
|
|
|
7950
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
extends 'Connector'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'BASECONNECTOR' => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
required => 1, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has '+LOCATION' => ( required => 0 ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Build arrayref from target the first time it is required |
28
|
|
|
|
|
|
|
has _target => ( is => 'rw', isa => 'ArrayRef|Undef', writer => '__target' ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has TARGET => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
isa => 'Connector::Types::Key|ArrayRef|Undef', |
33
|
|
|
|
|
|
|
trigger => sub { |
34
|
|
|
|
|
|
|
my ($self, $target) = @_; |
35
|
|
|
|
|
|
|
my @target = $self->_build_path( $target ); |
36
|
|
|
|
|
|
|
$self->__target( \@target ); |
37
|
|
|
|
|
|
|
# Force rebuild of prefix |
38
|
|
|
|
|
|
|
$self->PREFIX( $self->PREFIX() ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# override the prefix trigger to prepend the wrapper prefix |
43
|
|
|
|
|
|
|
has '+PREFIX' => ( |
44
|
|
|
|
|
|
|
trigger => sub { |
45
|
|
|
|
|
|
|
my ($self, $prefix, $old_prefix) = @_; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
if (not $self->TARGET) { |
48
|
|
|
|
|
|
|
$self->log()->debug( 'prefix before target - skipping!' ) ; |
49
|
|
|
|
|
|
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if (defined $prefix) { |
53
|
|
|
|
|
|
|
my @path = $self->_build_path($prefix); |
54
|
|
|
|
|
|
|
$self->__prefix_path( [ @{$self->_target()}, @path ]); |
55
|
|
|
|
|
|
|
} else { |
56
|
|
|
|
|
|
|
$self->__prefix_path( $self->_target() ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _route_call { |
63
|
|
|
|
|
|
|
|
64
|
26
|
|
|
26
|
|
29
|
my $self = shift; |
65
|
26
|
|
|
|
|
34
|
my $call = shift; |
66
|
26
|
|
|
|
|
29
|
my $path = shift; |
67
|
26
|
|
|
|
|
40
|
my @args = @_; |
68
|
|
|
|
|
|
|
|
69
|
26
|
|
|
|
|
70
|
my @fullpath = $self->_build_path_with_prefix( $path ); |
70
|
|
|
|
|
|
|
|
71
|
26
|
|
|
|
|
58
|
unshift @args, \@fullpath; |
72
|
|
|
|
|
|
|
|
73
|
26
|
|
|
|
|
648
|
return $self->BASECONNECTOR()->$call( @args ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Proxy calls |
78
|
|
|
|
|
|
|
sub get { |
79
|
22
|
|
|
22
|
1
|
59
|
my $self = shift; |
80
|
22
|
|
|
|
|
43
|
unshift @_, 'get'; |
81
|
22
|
|
|
|
|
49
|
return $self->_route_call( @_ ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_list { |
85
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
86
|
2
|
|
|
|
|
5
|
unshift @_, 'get_list'; |
87
|
2
|
|
|
|
|
17
|
return $self->_route_call( @_ ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub get_size { |
91
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
92
|
0
|
|
|
|
|
0
|
unshift @_, 'get_size'; |
93
|
0
|
|
|
|
|
0
|
return $self->_route_call( @_ ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_hash { |
97
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
98
|
2
|
|
|
|
|
5
|
unshift @_, 'get_hash'; |
99
|
2
|
|
|
|
|
6
|
return $self->_route_call( @_ ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub get_keys { |
103
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
104
|
0
|
|
|
|
|
|
unshift @_, 'get_keys'; |
105
|
0
|
|
|
|
|
|
return $self->_route_call( @_ ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub set { |
109
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
110
|
0
|
|
|
|
|
|
unshift @_, 'set'; |
111
|
0
|
|
|
|
|
|
return $self->_route_call( @_ ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub get_meta { |
115
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
116
|
0
|
|
|
|
|
|
unshift @_, 'get_meta'; |
117
|
0
|
|
|
|
|
|
return $self->_route_call( @_ ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub exists { |
121
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
122
|
0
|
|
|
|
|
|
unshift @_, 'exists'; |
123
|
0
|
|
|
|
|
|
return $self->_route_call( @_ ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
13
|
|
|
13
|
|
98
|
no Moose; |
|
13
|
|
|
|
|
34
|
|
|
13
|
|
|
|
|
76
|
|
127
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
__END__ |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 Name |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Connector |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 Description |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This provides a wrapper to the connector with a fixed prefix. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 Supported methods |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
get, get_list, get_size, get_hash, get_keys, set, meta |