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
|
|
103
|
use strict; |
|
13
|
|
|
|
|
42
|
|
|
13
|
|
|
|
|
402
|
|
13
|
13
|
|
|
13
|
|
75
|
use warnings; |
|
13
|
|
|
|
|
56
|
|
|
13
|
|
|
|
|
300
|
|
14
|
13
|
|
|
13
|
|
89
|
use English; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
73
|
|
15
|
13
|
|
|
13
|
|
4469
|
use Moose; |
|
13
|
|
|
|
|
38
|
|
|
13
|
|
|
|
|
81
|
|
16
|
13
|
|
|
13
|
|
84871
|
use Data::Dumper; |
|
13
|
|
|
|
|
6893
|
|
|
13
|
|
|
|
|
9527
|
|
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
|
|
37
|
my $self = shift; |
65
|
26
|
|
|
|
|
39
|
my $call = shift; |
66
|
26
|
|
|
|
|
40
|
my $path = shift; |
67
|
26
|
|
|
|
|
46
|
my @args = @_; |
68
|
|
|
|
|
|
|
|
69
|
26
|
|
|
|
|
73
|
my @fullpath = $self->_build_path_with_prefix( $path ); |
70
|
|
|
|
|
|
|
|
71
|
26
|
|
|
|
|
60
|
unshift @args, \@fullpath; |
72
|
|
|
|
|
|
|
|
73
|
26
|
|
|
|
|
823
|
return $self->BASECONNECTOR()->$call( @args ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Proxy calls |
78
|
|
|
|
|
|
|
sub get { |
79
|
22
|
|
|
22
|
1
|
81
|
my $self = shift; |
80
|
22
|
|
|
|
|
51
|
unshift @_, 'get'; |
81
|
22
|
|
|
|
|
52
|
return $self->_route_call( @_ ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_list { |
85
|
2
|
|
|
2
|
1
|
6
|
my $self = shift; |
86
|
2
|
|
|
|
|
5
|
unshift @_, 'get_list'; |
87
|
2
|
|
|
|
|
6
|
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
|
6
|
my $self = shift; |
98
|
2
|
|
|
|
|
6
|
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
|
|
131
|
no Moose; |
|
13
|
|
|
|
|
38
|
|
|
13
|
|
|
|
|
94
|
|
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 |