Connector

 view release on metacpan or  search on metacpan

lib/Connector/Wrapper.pm  view on Meta::CPAN

# Connector::Wrapper
#
# Wrapper class to filter access to a connector by a prefix 
#
# Written by Oliver Welter for the OpenXPKI project 2012
#
# TODO: To make this really transparent it need to be inherited 
# from Connector and implement the prefix stuff 

package Connector::Wrapper;

use strict;
use warnings;
use English;
use Moose;
use Data::Dumper;

extends 'Connector';

has 'BASECONNECTOR' => ( 
    is => 'ro', 
    required => 1, 
);

has '+LOCATION' => ( required => 0 );

# Build arrayref from target the first time it is required
has _target => ( is => 'rw', isa => 'ArrayRef|Undef', writer => '__target' );

has TARGET => ( 
    is => 'ro', 
    isa => 'Connector::Types::Key|ArrayRef|Undef', 
    trigger => sub {
        my ($self, $target) = @_;    
        my @target = $self->_build_path( $target );
        $self->__target( \@target );
        # Force rebuild of prefix 
        $self->PREFIX( $self->PREFIX() );
    }
);

# override the prefix trigger to prepend the wrapper prefix
has '+PREFIX' => (
    trigger => sub {
        my ($self, $prefix, $old_prefix) = @_;
        
        if (not $self->TARGET) {
            $self->log()->debug( 'prefix before target - skipping!' ) ;
            return;
        }
        
        if (defined $prefix) {
            my @path = $self->_build_path($prefix);
            $self->__prefix_path( [ @{$self->_target()}, @path ]);
        } else {
            $self->__prefix_path( $self->_target() );
        }   
    }
);


sub _route_call {
    
    my $self = shift;
    my $call = shift;
    my $path = shift;
    my @args = @_;



( run in 2.123 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )