NAME

Net::Stripe::Simple::Data - collection of methods to augment a JSON hash

SYNOPSIS

my $subscription = $stripe->subscriptions(  # API methods give us data objects
    update => {
        customer => $customer,              # a data object as a parameter value
        id       => $subscription,          # and another
        plan     => $spare_plan,            # and another
    }
);

DESCRIPTION

Net::Stripe::Simple::Data is simply a JSON hash with a little magic added to it. Principally, it will autoload any attribute name into an accessor method. So you can say

$data->id

instead of

$data->{id}

This magic is applied recursively, so instead of

$data->{metadata}{foo}

you can type

$data->metadata->foo

This hardly saves any keystrokes but it is arguably easier to read.

The second bit of magic is that the stringification operator is overloaded so that data objects with an id attribute are stringified as their id rather than as

Net::Stripe::Simple::Data=HASH(0xfeefaaf00)

This is useful because Stripe expects to see lots of different ids in its various methods, so you can type

$stripe->subscriptions(
    update => {
        customer => $customer,
        id       => $subscription,
        plan     => $spare_plan,
    }
);

instead of

$stripe->subscriptions(
    update => {
        customer => $customer->id,
        id       => $subscription->id,
        plan     => $spare_plan->id,
    }
);

or worse yet

$stripe->subscriptions(
    update => {
        customer => $customer->{id},
        id       => $subscription->{id},
        plan     => $spare_plan->{id},
    }
);

The 'cmp' operator is overloaded as well so the stringification works mostly as you expect. I.e.,

$data eq $string;

is equivalent to

$string eq $data;

NAME

Net::Stripe::Simple::Data - collection of methods to augment a JSON hash

METHODS

$self->unbless

Returns a copy of the data with all the magic stripped away. JSON objects are converted to their stringified form. The intended use of this is prettier debugging dumps.

AUTHORS

  • Grant Street Group <developers@grantstreet.com>

  • David F. Houghton <dfhoughton@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Grant Street Group.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

AUTHORS

  • Grant Street Group <developers@grantstreet.com>

  • David F. Houghton <dfhoughton@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Grant Street Group.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.