MooseY::RemoteHelper::Role::Client - Commonly used attributes for remote facade's
version 0.001021
use 5.010; # implementers use Moose; use Module::Runtime 'use_module'; use Try::Tiny; with 'MooseY::RemoteHelper::Role::Client'; sub submit { my ( $self, $req ) = @_; # check test # check debug and output request/response # ... my $res; # = ... return $res; } # consumers debbuging live transactions my $req; # your request object my $client = use_module('My::Client')->new({ user => 'Str', pass => 'Str', test => 0, debug => 1, }); my $res = try { $client->submit( $req ) } catch { # ... # if $_->does('Throwable') # ... };
I've found that most remote clients have the same things in common, "user", "pass", a way to transmit "submit", need for "debug" modes, and commonly a "test" mode.
Type: Str Required
This should be the username or other credential used to identify your user.
This should be the password, passphrase, or other credential used to authenticate your user initially. If for some reason your client doesn't have this, set it to an empty string and ignore it in "submit" method.
Type: Int Default: $ENV{REMOTE_CLIENT_DEBUG} or 0
$ENV{REMOTE_CLIENT_DEBUG}
0
This is used to provide debugging levels, it defaults to the Environment variable REMOTE_CLIENT_DEBUG or 0 if that's not set.
REMOTE_CLIENT_DEBUG
Type: Bool Default: 1
1
Many remote APIs have a test mode, that is different from live transactions. Use this to turn that on. It could toggle a different endpoint, or simply a parameter. Defaults to 1 because it's better to send fake requests than accidentally send live ones. Remember to always set this on APIs that use it.
my $res = try { $client->submit( $req ) } catch { ... if $_->does('Throwable') };
The above is the method signature this should implement. Submit should take a request object that can serialize and return a response object. Throwable exceptions should occur if there is a network transmission error.
Note: the sample usage here is not good, write your exception handling better than this.
Please report any bugs or feature requests on the bugtracker website https://github.com/xenoterracide/moosex-remotehelper/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Please see those modules/websites for more information related to this module.
MooseX::RemoteHelper
Caleb Cushing <xenoterracide@gmail.com>
This software is Copyright (c) 2013 by Caleb Cushing.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install MooseX::RemoteHelper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::RemoteHelper
CPAN shell
perl -MCPAN -e shell install MooseX::RemoteHelper
For more information on module installation, please visit the detailed CPAN module installation guide.