Paws::Net::MultiplexCaller - Control routing of services to Paws callers
use Paws::Net::MultiplexCaller; use Paws::Net::LWPCaller; use Paws::Net::MockCaller; my $paws = Paws->new( config => { caller => Paws::Net::MultiplexCaller->new( caller_for => { SQS => Paws::Net::LWPCaller->new(), EC2 => Paws::Net::MockCaller->new(...), }, default_caller => Paws::Net::Caller->new ) } ); # SQS methods will be called with LWPCaller # $paws->service('SQS', region => 'eu-west-1')->CreateQueue # EC2 with the MockCaller # $paws->service('EC2', region => 'us-east-1')->RunInstances # others will be called with the default Paws::Net::Caller # $paws->service('DynamoDB', region => 'us-east-1')->CreateTable
By default, Paws routes all calls to service methods (RunInstances for EC2 and CreateQueue for SQS, for example) to the configured caller (that normally will do HTTP requests to the backing services). All calls go to the one and only caller.
Paws::Net::MultiplexCaller is one of Paws' pluggable callers whose only purpose is to let you route requests to different callers. So you can do special things like:
Attributes are initialized in the constructor
Is a Hashref which keys are the names of the services to route for. It's values are instances of objects that can handle Paws calls (it's pluggable callers). Note that you can pass the same object for different services
my $caller2 = Paws::Net::LWPCaller->new; my $paws = Paws->new( config => { caller => Paws::Net::MultiplexCaller->new( caller_for => { SQS => $caller2, EC2 => $caller2, }, ) } );
As opposed to
my $paws = Paws->new( config => { caller => Paws::Net::MultiplexCaller->new( caller_for => { SQS => Paws::Net::LWPCaller->new, EC2 => Paws::Net::LWPCaller->new, }, ) } );
Where there would be two independant instances of LWPCaller (consuming double memory), or leading to unexpected results (should the callers track some sort of state, like Paw::Net::MockCaller)
If not specified, any call to a service that is not in caller_for will fail to complete, raising an exception.
caller_for
If specified, Paws will route any service that is not in caller_for to this caller, that should be initialized to an instance of any of Paws' pluggable callers.
On CPAN you can find Paws::Kinesis::MemoryCaller, that emulates the AWS Kinesis service. Using that caller will not let you call other AWS services. With Paws::Net::MultiplexCaller we can solve that:
Paws::Net::MultiplexCaller
my $paws = Paws->new( config => { caller => Paws::Net::MultiplexCaller->new( caller_for => { Kinesis => Paws::Kinesis::MemoryCaller->new(), }, default_caller => Paws::Net::Caller->new ) } );
You can also combine the multiplex caller with PawsX::FakeImplementation::Instance to easily fake some AWS services for your testing purposes.
Jose Luis Martinez CPAN ID: JLMARTIN CAPSiDE jlmartinez@capside.com
Paws
Paws::Kinesis::MemoryCaller
PawsX::FakeImplementation::Instance
The source code is located here: https://github.com/pplu/paws-net-multiplexcaller
Please report bugs to: https://github.com/pplu/paws-net-multiplexcaller/issues
Copyright (c) 2017 by CAPSiDE
This code is distributed under the Apache 2 License. The full text of the license can be found in the LICENSE file included with this module.
To install Paws::Net::MultiplexCaller, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Paws::Net::MultiplexCaller
CPAN shell
perl -MCPAN -e shell install Paws::Net::MultiplexCaller
For more information on module installation, please visit the detailed CPAN module installation guide.