Stripe/Resource.pm

filter: Statementstmt 91.8% 147 / 160 Branchbran 48.2% 54 / 112 Conditioncond 37.9% 11 / 29 MC/DCmcdc 12.5% 2 / 16 Subroutinesub 100% 21 / 21 Podpod n/a totaltotal 69.5% 235 / 338 CC 71 SCAR 35.0
CC
71
Cov
70%
__ANON__
93.2
fields_for
26.0
get_form_field_value
12.3
CRAP 33.1
« Stripe/Customer.pm ↑ Summary Stripe/Invoice.pm »
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
BranchTrueFalseTotal
@_ == 1 ? : 1 12 13
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
BranchTrueFalseTotal
if (ref($args{$field}) =~ /^(JSON::XS::Boolean|JSON::PP::Boolean)$/) 0 21 21
18 0 ▶ $args{$field} = $args{$field} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args{$field} ? : 0 0 0
19 }
20 }
21  
22 13 ▶ if (my $s = $args{source}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $args{"source"}) 0 13 13
23 0 ▶ if (ref($s) eq 'HASH' && $s->{object} eq 'source') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s eq "HASH" and $s->{"object"} eq "source") 0 0 0
Condition0%0/3
ref $s eq "HASH" and $s->{"object"} eq "source"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $args{$f} 25 1 26
30 1 ▶ next unless ref($args{$f}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{$f} eq "HASH" 1 0 1
31 0 $args{$f} = Net::Stripe::Card->new($args{$f});
32 }
33  
34 13 ▶ if (my $s = $args{subscription}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $args{"subscription"}) 0 13 13
35 0 ▶ if (ref($s) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s eq "HASH") 0 0 0
36 0 $args{subscription} = Net::Stripe::Subscription->new($s);
37 }
38 }
39 13 ▶ if (my $s = $args{coupon}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $args{"coupon"}) 0 13 13
40 0 ▶ if (ref($s) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s eq "HASH") 0 0 0
41 0 $args{coupon} = Net::Stripe::Coupon->new($s);
42 }
43 }
44 13 ▶ if (my $s = $args{discount}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $args{"discount"}) 0 13 13
45 0 ▶ if (ref($s) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s eq "HASH") 0 0 0
46 0 $args{discount} = Net::Stripe::Discount->new($s);
47 }
48 }
49 13 ▶ if (my $p = $args{plan}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = $args{"plan"}) 0 13 13
50 0 ▶ if (ref($p) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $p eq "HASH") 0 0 0
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
BranchTrueFalseTotal
unless $attr->type_constraint and $attr->type_constraint eq "Bool" || $attr->type_constraint eq "Maybe[Bool]" || $attr->type_constraint eq "Maybe[Bool|Object]" 248 14 262
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]"
!ll&&!rl&&r
1223614
$attr->type_constraint eq "Bool" or $attr->type_constraint eq "Maybe[Bool]" or $attr->type_constraint eq "Maybe[Bool|Object]"
l!l&&r!l&&!r
014236
$attr->type_constraint eq "Bool" or $attr->type_constraint eq "Maybe[Bool]"
l!l&&r!l&&!r
00250
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]"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
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
BranchTrueFalseTotal
if @_ != 2 0 2 2
$#_ >= 0 ? : 2 0 2
if ($#_ >= 0) 2 0 2
Type::Tiny::XS::Str($field_name) or _failed_check(14, "Str", $field_name, "exception_class", "Error::TypeTiny::Assertion") 2 0 2
$#_ >= 1 ? : 2 0 2
if ($#_ >= 1) 2 0 2
Ref::Util::XS::is_plain_hashref($hashref) or _failed_check(27, "HashRef", $hashref, "exception_class", "Error::TypeTiny::Assertion") 2 0 2
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
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 1 1 2
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
BranchTrueFalseTotal
if @_ != 2 0 1 1
$#_ >= 0 ? : 1 0 1
if ($#_ >= 0) 1 0 1
Type::Tiny::XS::Str($field_name) or _failed_check(14, "Str", $field_name, "exception_class", "Error::TypeTiny::Assertion") 1 0 1
$#_ >= 1 ? : 1 0 1
if ($#_ >= 1) 1 0 1
Ref::Util::XS::is_plain_arrayref($arrayref) or _failed_check(26, "ArrayRef", $arrayref, "exception_class", "Error::TypeTiny::Assertion") 1 0 1
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
BranchTrueFalseTotal
@_ ? : 26 0 26
if @_ != 1 0 26 26
$#_ >= 0 ? : 26 0 26
93 26 ▶ return unless $self->can($for);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($for) 0 26 26
94 26 my $thingy = $self->$for;
95 26 ▶ return unless defined( $thingy );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thingy 24 2 26
96 2 ▶ return ($for => $thingy->id) if $for eq 'card' && ref($thingy) eq 'Net::Stripe::Token';
Branch: 1 branch
BranchTrueFalseTotal
if $for eq "card" and ref $thingy eq "Net::Stripe::Token" 0 2 2
Condition33%1/3
$for eq "card" and ref $thingy eq "Net::Stripe::Token"
!ll&&!rl&&r
200
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"
ABresult
0X0
100
111
97 2 ▶ return ($for => $thingy->id) if $for eq 'source' && ref($thingy) eq 'Net::Stripe::Token';
Branch: 1 branch
BranchTrueFalseTotal
if $for eq "source" and ref $thingy eq "Net::Stripe::Token" 0 2 2
Condition33%1/3
$for eq "source" and ref $thingy eq "Net::Stripe::Token"
!ll&&!rl&&r
200
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"
ABresult
0X0
100
111
98 2 ▶ return $thingy->form_fields if ref($thingy) =~ m/^Net::Stripe::/;
Branch: 1 branch
BranchTrueFalseTotal
if ref($thingy) =~ /^Net::Stripe::/ 0 2 2
99 2 ▶ return form_fields_for_hashref( $for, $thingy ) if ref( $thingy ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $thingy eq "HASH" 0 2 2
100 2 ▶ return form_fields_for_arrayref( $for, $thingy ) if ref( $thingy ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $thingy eq "ARRAY" 0 2 2
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
BranchTrueFalseTotal
if $self->isa("Net::Stripe::PaymentMethod") and $for eq "card" and $token_id_type->check($thingy) 0 2 2
Condition33%2/6
$self->isa("Net::Stripe::PaymentMethod") and $for eq "card" and $token_id_type->check($thingy)
!ll&&!rl&&r
200
$self->isa("Net::Stripe::PaymentMethod") and $for eq "card"
!ll&&!rl&&r
200
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)
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
@_ ? : 2 0 2
$#_ >= 0 ? : 2 0 2
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
BranchTrueFalseTotal
@_ ? : 2 0 2
if @_ != 1 0 2 2
$#_ >= 0 ? : 2 0 2
if ($#_ >= 0) 2 0 2
Type::Tiny::XS::Str($attr) or _failed_check(14, "Str", $attr, "exception_class", "Error::TypeTiny::Assertion") 2 0 2
114 2 ▶ my %boolean_attributes = map { $_ => 1 } @{$self->boolean_attributes() || []};
Condition50%1/2
$self->boolean_attributes || []
l!l
20
MC/DC0%0/1
$self->boolean_attributes || []
$self->boolean_attributes
Truth table50%1/2
A
A= $self->boolean_attributes
Aresult
11
00
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
BranchTrueFalseTotal
@_ ? : 2 0 2
if @_ != 1 0 2 2
$#_ >= 0 ? : 2 0 2
if ($#_ >= 0) 2 0 2
Type::Tiny::XS::Str($attr) or _failed_check(14, "Str", $attr, "exception_class", "Error::TypeTiny::Assertion") 2 0 2
119 2 my $value = $self->$attr;
120 2 ▶ return $value if ! $self->is_a_boolean( $attr );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_a_boolean($attr) 2 0 2
121 0 ▶ return ( defined( $value ) && $value ) ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
defined $value && $value ? : 0 0 0
Condition0%0/3
defined $value and $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and $value
defined $value $value
Truth table0%0/3
A and B
A= defined $valueB= $value
ABresult
0X0
100
111
122 }
123  
124 2 1;
125  
126 __END__
« Stripe/Customer.pm ↑ Summary Stripe/Invoice.pm »