AvaTax::BUILD method Modifies Perl Stash For All Class Instances #1

Open
opened 2017-07-31 16:03:39 +00:00 by elderling · 0 comments
elderling commented 2017-07-31 16:03:39 +00:00 (Migrated from github.com)

WebService::Avalara::AvaTax::BUILD uses the Package::Stash module to add Perl-native subroutines to the WebService::Avalara::AvaTax package every time an instance is created. This approach causes action a distance for every AvaTax instance. For example,

my $avatax = WebService::Avalara::AvaTax->new(
    username => 'username',
    password => 'password',
);

my $avatax_orthodox = WebService::Avalara::AvaTax->new(
    username => 'username',
    password => 'password',
    orthodox => 1,
);

# Returns both orthodox and unorthodox methods because the BUILD
# method adds them to the package stash shared by both instances
say($_) for keys %{$avatax->_stash->get_all_symbols};

A more troubling example:

my $avatax = WebService::Avalara::AvaTax->new(
    username => 'good_username',
    password => 'good_password',
);

$answer_ref = $avatax->ping; # success

my $avatax_bad_creds = WebService::Avalara::AvaTax->new(
    username => 'good_username',
    password => 'BAD_password',
);

# Notice that the following is the original $avatax instance. The
# instantiation of $avatax_bad_creds instance overwrote the Perl Package
# Stash and invalidated the $avatax instance.
$answer_ref = $avatax->ping; # FAIL due to bad credentials

I conjecture that the use of Package::Stash was expected to provide MOP-like
object mutation rather than class mutation.

`WebService::Avalara::AvaTax::BUILD` uses the `Package::Stash` module to add Perl-native subroutines to the `WebService::Avalara::AvaTax` package every time an instance is created. This approach causes action a distance for *every* `AvaTax` instance. For example, my $avatax = WebService::Avalara::AvaTax->new( username => 'username', password => 'password', ); my $avatax_orthodox = WebService::Avalara::AvaTax->new( username => 'username', password => 'password', orthodox => 1, ); # Returns both orthodox and unorthodox methods because the BUILD # method adds them to the package stash shared by both instances say($_) for keys %{$avatax->_stash->get_all_symbols}; A more troubling example: my $avatax = WebService::Avalara::AvaTax->new( username => 'good_username', password => 'good_password', ); $answer_ref = $avatax->ping; # success my $avatax_bad_creds = WebService::Avalara::AvaTax->new( username => 'good_username', password => 'BAD_password', ); # Notice that the following is the original $avatax instance. The # instantiation of $avatax_bad_creds instance overwrote the Perl Package # Stash and invalidated the $avatax instance. $answer_ref = $avatax->ping; # FAIL due to bad credentials I conjecture that the use of `Package::Stash` was expected to provide MOP-like object mutation rather than class mutation.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mjg/perl-WebService-Avalara-AvaTax#1
No description provided.