| 1 | package Net::Stripe::Resource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | $Net::Stripe::Resource::VERSION = '0.43'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: represent a Resource object from Stripe | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Kavorka; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | has 'boolean_attributes' => (is => 'ro', isa => 'ArrayRef[Str]'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=24 SCAR=45.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | my %args = @_ == 1 ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Break out the JSON::XS::Boolean values into 1/0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | for my $field (keys %args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 21 | ▶ | if (ref($args{$field}) =~ /^(JSON::XS::Boolean|JSON::PP::Boolean)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $args{$field} = $args{$field} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 13 | ▶ | if (my $s = $args{source}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | if (ref($s) eq 'HASH' && $s->{object} eq 'source') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $s eq "HASH" and $s->{"object"} eq "source"
MC/DC0%0/2
ref $s eq "HASH" and $s->{"object"} eq "source"
ref $s eq "HASH"
$s->{"object"} eq "source"
Truth table0%0/3
A and B
A= ref $s eq "HASH"B= $s->{"object"} eq "source"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | $args{source} = Net::Stripe::Source->new($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 13 | for my $f (qw/card default_card/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 26 | ▶ | next unless $args{$f}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | next unless ref($args{$f}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $args{$f} = Net::Stripe::Card->new($args{$f}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 13 | ▶ | if (my $s = $args{subscription}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if (ref($s) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $args{subscription} = Net::Stripe::Subscription->new($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 13 | ▶ | if (my $s = $args{coupon}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (ref($s) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $args{coupon} = Net::Stripe::Coupon->new($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | ▶ | if (my $s = $args{discount}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if (ref($s) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $args{discount} = Net::Stripe::Discount->new($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 13 | ▶ | if (my $p = $args{plan}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (ref($p) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $args{plan} = Net::Stripe::Plan->new($p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 13 | for my $attr ($class->meta()->get_all_attributes()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 262 | ▶ | next if !($attr->type_constraint && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$attr->type_constraint and $attr->type_constraint eq "Bool" || $attr->type_constraint eq "Maybe[Bool]" || $attr->type_constraint eq "Maybe[Bool|Object]"
$attr->type_constraint eq "Bool" or $attr->type_constraint eq "Maybe[Bool]" or $attr->type_constraint eq "Maybe[Bool|Object]"
$attr->type_constraint eq "Bool" or $attr->type_constraint eq "Maybe[Bool]"
MC/DC50%2/4
$attr->type_constraint and $attr->type_constraint eq "Bool" || $attr->type_constraint eq "Maybe[Bool]" || $attr->type_constraint eq "Maybe[Bool|Object]"
$attr->type_constraint
$attr->type_constraint eq "Bool"
$attr->type_constraint eq "Maybe[Bool]"
$attr->type_constraint eq "Maybe[Bool|Object]"
Truth table60%3/5
A and B or C or D
A= $attr->type_constraintB= $attr->type_constraint eq "Bool"C= $attr->type_constraint eq "Maybe[Bool]"D= $attr->type_constraint eq "Maybe[Bool|Object]"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | $attr->type_constraint eq 'Bool' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $attr->type_constraint eq 'Maybe[Bool]' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $attr->type_constraint eq 'Maybe[Bool|Object]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 14 | push @{$args{boolean_attributes}}, $attr->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | $class->$orig(%args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | fun form_fields_for_hashref ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | Str $field_name!, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | HashRef $hashref!, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
form_fields_for_hashref: called CC=10 SCAR=23.4
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | my @field_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | foreach my $key (sort keys %$hashref) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | my $value = $hashref->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | my $nested_field_name = sprintf( '%s[%s]', $field_name, $key ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | if ( ref( $value ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | push @field_values, form_fields_for_hashref( $nested_field_name, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | push @field_values, ( $nested_field_name => $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | return @field_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | fun form_fields_for_arrayref ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | Str $field_name!, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ArrayRef $arrayref!, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | ▶ | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
form_fields_for_arrayref: called CC=8 SCAR=21.3
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | my $nested_field_name = sprintf( '%s[]', $field_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | return $nested_field_name => $arrayref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | method fields_for($for) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
fields_for: called CC=16 SCAR=32.6
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 26 | ▶ | return unless $self->can($for); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 26 | my $thingy = $self->$for; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 26 | ▶ | return unless defined( $thingy ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | return ($for => $thingy->id) if $for eq 'card' && ref($thingy) eq 'Net::Stripe::Token'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$for eq "card" and ref $thingy eq "Net::Stripe::Token"
MC/DC0%0/2
$for eq "card" and ref $thingy eq "Net::Stripe::Token"
$for eq "card"
ref $thingy eq "Net::Stripe::Token"
Truth table33%1/3
A and B
A= $for eq "card"B= ref $thingy eq "Net::Stripe::Token"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | return ($for => $thingy->id) if $for eq 'source' && ref($thingy) eq 'Net::Stripe::Token'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$for eq "source" and ref $thingy eq "Net::Stripe::Token"
MC/DC0%0/2
$for eq "source" and ref $thingy eq "Net::Stripe::Token"
$for eq "source"
ref $thingy eq "Net::Stripe::Token"
Truth table33%1/3
A and B
A= $for eq "source"B= ref $thingy eq "Net::Stripe::Token"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | ▶ | return $thingy->form_fields if ref($thingy) =~ m/^Net::Stripe::/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | return form_fields_for_hashref( $for, $thingy ) if ref( $thingy ) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | return form_fields_for_arrayref( $for, $thingy ) if ref( $thingy ) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | my $token_id_type = Moose::Util::TypeConstraints::find_type_constraint( 'StripeTokenId' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | return form_fields_for_hashref( $for, { token => $thingy } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->isa("Net::Stripe::PaymentMethod") and $for eq "card" and $token_id_type->check($thingy)
$self->isa("Net::Stripe::PaymentMethod") and $for eq "card"
MC/DC0%0/3
$self->isa("Net::Stripe::PaymentMethod") and $for eq "card" and $token_id_type->check($thingy)
$self->isa("Net::Stripe::PaymentMethod")
$for eq "card"
$token_id_type->check($thingy)
Truth table25%1/4
A and B and C
A= $self->isa("Net::Stripe::PaymentMethod")B= $for eq "card"C= $token_id_type->check($thingy)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | if $self->isa( 'Net::Stripe::PaymentMethod' ) && $for eq 'card' && $token_id_type->check( $thingy ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | return ( $for => $self->get_form_field_value( $for ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | ▶ | method form_fields_for(@fields!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
form_fields_for: called CC=3 SCAR=11.1
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | return map { $self->fields_for( $_ ) } @fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | method is_a_boolean(Str $attr!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
is_a_boolean: called CC=7 SCAR=20.0
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | my %boolean_attributes = map { $_ => 1 } @{$self->boolean_attributes() || []}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->boolean_attributes || []
MC/DC0%0/1
$self->boolean_attributes || []
$self->boolean_attributes
Truth table50%1/2
A
A= $self->boolean_attributes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | return exists( $boolean_attributes{$attr} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | method get_form_field_value(Str $attr!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
get_form_field_value: called CC=9 SCAR=25.1
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | my $value = $self->$attr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | return $value if ! $self->is_a_boolean( $attr ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | return ( defined( $value ) && $value ) ? 'true' : 'false'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and $value
MC/DC0%0/2
defined $value and $value
defined $value
$value
Truth table0%0/3
A and B
A= defined $valueB= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||