Business-Shipping
view release on metacpan or search on metacpan
t/910-Interchange-sim.t view on Meta::CPAN
#!/bin/env perl
=head1 NAME
Simulator for Business::Shipping Interchange UserTag
=head1 VERSION
This is simulator version 221, which is based on usertag version 1.13.
=head1 DESCRIPTION
Tests the module within a certain context: an Interchange UserTag (see
C<UserTag/business-shipping.tag>).
This is a copy/paste of the usertag, with several changes:
=over 4
=item * Interchange Variables and Values simulation
=item * Interchange "$Tag->___()" simulation
=item * Simulation of other Interchange facilities.
=back
Eventually, it should run a gamut of tests, for all modules, etc.
=cut
use version; our $VERSION = qv('2.4.0');
use strict;
use warnings;
use Test::More;
plan skip_all => 'missing required modules'
unless Business::Shipping::Config::calc_req_mod('UPS_Online');
plan skip_all => ''
unless Business::Shipping::Config::calc_req_mod('USPS_Online');
plan skip_all => ''
unless Business::Shipping::Config::calc_req_mod('UPS_Offline');
plan skip_all => 'No credentials'
unless $ENV{UPS_USER_ID}
and $ENV{UPS_PASSWORD}
and $ENV{UPS_ACCESS_KEY};
plan 'no_plan';
# Setup Interchange Environment Simulation
use Data::Dumper;
our $Values = {};
our $Variable = {};
our $Session = {};
$Variable->{BSHIPPING_MAX_WEIGHT} = 75;
package Nothing;
sub Nothing::data { return ''; }
our $Tag = bless({}, "Nothing")
; # TODO: add the 'data' routine that will return a sample value.
package main;
sub Log { print $_[0] . "\n" }
sub uneval { return Dumper(@_); }
###############################################################################
## Begin contents of business-shipping.tag
###############################################################################
use Business::Shipping 2.4.0; # For 'all/shop' support.
sub tag_business_shipping {
my ($shipper, $opt) = @_;
my $debug = delete $opt->{debug} || $Variable->{BSHIPPING_DEBUG} || 0;
$shipper ||= delete $opt->{shipper} || '';
::logDebug(
"[business-shipping $shipper" . Vend::Util::uneval_it($opt) . " ]")
if $debug;
my $try_limit = delete $opt->{'try_limit'} || 2;
delete $opt->{shipper};
unless ($shipper and $opt->{weight} and $opt->{'service'}) {
Log("mode, weight, and service required");
return;
}
# We pass the options mostly unmodifed to the underlying library, so here we
# take out anything Interchange-specific that isn't necessary using a hash
# slice.
delete @{$opt}{ 'reparse', 'mode', 'hide', 'shipper' };
# Business::Shipping takes a hash.
my %opt = %$opt;
$opt = undef;
my $to_country_default
= $Values->{ $Variable->{BSHIPPING_TO_COUNTRY_FIELD} || 'country' };
( run in 1.368 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )