Business-UPS-Tracking

 view release on metacpan or  search on metacpan

lib/Business/UPS/Tracking/Role/Base.pm  view on Meta::CPAN

# ============================================================================
package Business::UPS::Tracking::Role::Base;
# ============================================================================
use utf8;
use 5.0100;

use Moose::Role;

no if $] >= 5.017004, warnings => qw(experimental::smartmatch);

use Try::Tiny;
use Path::Class::File;

=encoding utf8

=head1 NAME

Business::UPS::Tracking::Role::Base - Helper role

=head1 DESCRIPTION

This role provides accessors for the UPS webservice credentials.
The credentials can be provided when constructing a new object, or optionally
stored in a configuration file.

=head1 ACCESSORS

=head2 AccessLicenseNumber

UPS tracking service access license number

=head2 UserId

UPS account username

=head2 Password

UPS account password

=head2 config

Optionally you can retrieve all or some UPS webservice credentials from a
configuration file. This accessor holds the path to this file.
Defaults to C<~/.ups_tracking>

Example configuration file:

 <?xml version="1.0"?>
 <UPS_tracing_webservice_config>
    <AccessLicenseNumber>1CFFED5A5E91B17</AccessLicenseNumber>
    <UserId>myupsuser</UserId>
    <Password>secret</Password>
 </UPS_tracing_webservice_config>

=cut

has 'config' => (
    is       => 'rw',
    isa      => 'Str',
    default  => sub {
        Path::Class::File->new( $ENV{HOME}, '.ups_tracking' )->stringify;
    },
    documentation => 'UPS tracking webservice access config file'
);

has 'AccessLicenseNumber' => (
    is          => 'rw',
    required    => 1,
    isa         => 'Str',
    lazy_build  => 1,
    predicate   => '_has_AccessLicenseNumber',
    documentation   => 'UPS webservice license number (Can be set via the ups_tracking config file)',
);
has 'UserId' => (
    is          => 'rw',
    isa         => 'Str',
    required    => 1,
    lazy_build  => 1,
    predicate   => '_has_UserId',
    documentation   => 'UPS webservice user id (Can be set via the ups_tracking config file)',
);
has 'Password' => (
    is          => 'rw',
    isa         => 'Str',
    required    => 1,
    lazy_build  => 1,
    predicate   => '_has_Password',
    documentation   => 'UPS webservice password (Can be set via the ups_tracking config file)',
);


sub _build_AccessLicenseNumber {
    my ($self) = @_;

    $self->_build_config();

    if ($self->_has_AccessLicenseNumber) {
        return $self->AccessLicenseNumber;
    }
}

sub _build_UserId {



( run in 0.524 second using v1.01-cache-2.11-cpan-39bf76dae61 )