| 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 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 11 | ▶ | use English; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 11 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 11 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 11 | extends 'Connector'; | |||||||||
| 19 | |||||||||||
| 20 | 11 | has 'BASECONNECTOR' => ( | |||||||||
| 21 | is => 'ro', | ||||||||||
| 22 | required => 1, | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 11 | has '+LOCATION' => ( required => 0 ); | |||||||||
| 26 | |||||||||||
| 27 | # Build arrayref from target the first time it is required | ||||||||||
| 28 | 11 | has _target => ( is => 'rw', isa => 'ArrayRef|Undef', writer => '__target' ); | |||||||||
| 29 | |||||||||||
| 30 | has TARGET => ( | ||||||||||
| 31 | is => 'ro', | ||||||||||
| 32 | isa => 'Connector::Types::Key|ArrayRef|Undef', | ||||||||||
| 33 | 8 | ▶ | trigger => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 8 | my ($self, $target) = @_; | |||||||||
| 35 | 8 | my @target = $self->_build_path( $target ); | |||||||||
| 36 | 8 | $self->__target( \@target ); | |||||||||
| 37 | # Force rebuild of prefix | ||||||||||
| 38 | 8 | $self->PREFIX( $self->PREFIX() ); | |||||||||
| 39 | } | ||||||||||
| 40 | 11 | ); | |||||||||
| 41 | |||||||||||
| 42 | # override the prefix trigger to prepend the wrapper prefix | ||||||||||
| 43 | has '+PREFIX' => ( | ||||||||||
| 44 | 9 | ▶ | trigger => sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||
| 45 | 9 | my ($self, $prefix, $old_prefix) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 9 | ▶ | if (not $self->TARGET) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | $self->log()->debug( 'prefix before target - skipping!' ) ; | |||||||||
| 49 | 0 | return; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 9 | ▶ | if (defined $prefix) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 1 | my @path = $self->_build_path($prefix); | |||||||||
| 54 | 1 | $self->__prefix_path( [ @{$self->_target()}, @path ]); | |||||||||
| 55 | } else { | ||||||||||
| 56 | 8 | $self->__prefix_path( $self->_target() ); | |||||||||
| 57 | } | ||||||||||
| 58 | } | ||||||||||
| 59 | 11 | ); | |||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | 26 | ▶ | sub _route_call { | ||||||||
|
Subroutine
_route_call: called CC=1 SCAR=0.0
| |||||||||||
| 63 | |||||||||||
| 64 | 26 | my $self = shift; | |||||||||
| 65 | 26 | my $call = shift; | |||||||||
| 66 | 26 | my $path = shift; | |||||||||
| 67 | 26 | my @args = @_; | |||||||||
| 68 | |||||||||||
| 69 | 26 | my @fullpath = $self->_build_path_with_prefix( $path ); | |||||||||
| 70 | |||||||||||
| 71 | 26 | unshift @args, \@fullpath; | |||||||||
| 72 | |||||||||||
| 73 | 26 | return $self->BASECONNECTOR()->$call( @args ); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | # Proxy calls | ||||||||||
| 78 | 22 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 79 | 22 | my $self = shift; | |||||||||
| 80 | 22 | unshift @_, 'get'; | |||||||||
| 81 | 22 | return $self->_route_call( @_ ); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 2 | ▶ | sub get_list { | ||||||||
|
Subroutine
get_list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 85 | 2 | my $self = shift; | |||||||||
| 86 | 2 | unshift @_, 'get_list'; | |||||||||
| 87 | 2 | return $self->_route_call( @_ ); | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | sub get_size { | ||||||||
|
Subroutine
get_size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 91 | 0 | my $self = shift; | |||||||||
| 92 | 0 | unshift @_, 'get_size'; | |||||||||
| 93 | 0 | return $self->_route_call( @_ ); | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 2 | ▶ | sub get_hash { | ||||||||
|
Subroutine
get_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 97 | 2 | my $self = shift; | |||||||||
| 98 | 2 | unshift @_, 'get_hash'; | |||||||||
| 99 | 2 | return $self->_route_call( @_ ); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 0 | ▶ | sub get_keys { | ||||||||
|
Subroutine
get_keys: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 103 | 0 | my $self = shift; | |||||||||
| 104 | 0 | unshift @_, 'get_keys'; | |||||||||
| 105 | 0 | return $self->_route_call( @_ ); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | sub set { | ||||||||
|
Subroutine
set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 109 | 0 | my $self = shift; | |||||||||
| 110 | 0 | unshift @_, 'set'; | |||||||||
| 111 | 0 | return $self->_route_call( @_ ); | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | 0 | ▶ | sub get_meta { | ||||||||
|
Subroutine
get_meta: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 115 | 0 | my $self = shift; | |||||||||
| 116 | 0 | unshift @_, 'get_meta'; | |||||||||
| 117 | 0 | return $self->_route_call( @_ ); | |||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | 0 | ▶ | sub exists { | ||||||||
|
Subroutine
exists: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 121 | 0 | my $self = shift; | |||||||||
| 122 | 0 | unshift @_, 'exists'; | |||||||||
| 123 | 0 | return $self->_route_call( @_ ); | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 11 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 127 | 11 | __PACKAGE__->meta->make_immutable; | |||||||||
| 128 | |||||||||||
| 129 | 11 | 1; | |||||||||
| 130 | __END__ | ||||||||||