stripe-perl
stripe-perl copied to clipboard
enable debugging options for Carp and Type::Tiny
i have found these to be very useful during development.
$Carp::Verbose = 1;
$Type::Tiny::DD = 999_999;
and can mean the difference between
Unknown named parameter: card at lib/Net/Stripe.pm line 2289.
and the much more useful
Unknown named parameter: card at lib/Net/Stripe/Resource.pm line 99, <DATA> line 1.
Net::Stripe::Resource::_form_fields_for_ref("card", HASH(0x6559fc8)) called at lib/Net/Stripe/PaymentMethod.pm line 59
Net::Stripe::PaymentMethod::card_token(Net::Stripe::PaymentMethod=HASH(0x68f7908)) called at lib/Net/Stripe/PaymentMethod.pm line 64
Net::Stripe::PaymentMethod::form_fields(Net::Stripe::PaymentMethod=HASH(0x68f7908)) called at lib/Net/Stripe.pm line 2289
Net::Stripe::_post(Net::Stripe=HASH(0x38b0ea8), "payment_methods", Net::Stripe::PaymentMethod=HASH(0x68f7908)) called at lib/Net/Stripe.pm line 1436
Net::Stripe::create_payment_method(Net::Stripe=HASH(0x38b0ea8), "type", "card", "card", "tok_1G4uorArgp8DNlGokHCvbSH4") called at t/live.t line 203
i usually just hack them in while i am working, and remove them before commit, but it might be useful to enable them dynamically based on the value of $stripe->debug.
FTR, Type::Tiny
is germane here because the Kavorka
converts any Moose::Util::TypeConstraints
used in method signatures into Type::Tiny
objects, and therefore that is where any message about invalid parameters are generated.
unfortunately, the above does not work for Kavorka
signature errors for TypeConstraints. and Type::Tiny doesn't currently support appending the stack trace to the emitted message.
even though it is a bit clunky, you can get at it
Stripe.pm
sub BUILD {
my ( $self, $args ) = @_;
if ( $self->debug ) {
$Carp::Verbose = 1;
$Type::Tiny::DD = 999_999;
$Error::TypeTiny::StackTrace = 1;
$SIG{__DIE__} = sub { warn $_[0]->stack_trace if ref( $_[0] ) eq 'Error::TypeTiny::Assertion'; die $_[0] };
}
}
Carp::cluck( "$e" ) if $self->debug;