blib/lib/PagSeguro/API.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 26 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 119 SCAR 57.2
CC
17
Cov
0%
new
42.0
transaction
20.0
notification
20.0
CRAP 306.0
1 package PagSeguro::API;
2 use strict;
3 use warnings;
4 our $VERSION = '0.004';
5  
6 use PagSeguro::API::Checkout;
7 use PagSeguro::API::Transaction;
8 use PagSeguro::API::Notification;
9  
10 # constructor
11 sub new {
12 my $class = shift;
13 my %args = @_ if (@_ % 2) == 0;
14  
15 # start resource
16 PagSeguro::API::Resource->instance;
17  
18 # check env vars
19 $args{email} = $ENV{PAGSEGURO_API_EMAIL} || undef
20 unless $args{email};
21  
22 $args{token} = $ENV{PAGSEGURO_API_TOKEN} || undef
23 unless $args{token};
24  
25 # enable sandbox
26 $ENV{PAGSEGURO_API_SANDBOX} = $args{sandbox}
27 if $args{sandbox};
28  
29 # enable debug
30 $ENV{PAGSEGURO_API_DEBUG} = $args{debug}
31 if $args{debug};
32  
33 return bless {
34 _email => $args{email} || undef,
35 _token => $args{token} || undef,
36  
37 _checkout => undef,
38 _transaction => undef,
39 _notification => undef,
40 }, $class;
41 }
42  
43 # accessors
44 sub email {
45 $_[0]->{_email} = $_[1] if $_[1];
46 return shift->{_email};
47 }
48  
49 sub token {
50 $_[0]->{_token} = $_[1] if $_[1];
51 return shift->{_token};
52 }
53  
54 # methods
55 sub transaction {
56 my $self = shift;
57  
58 # error
59 die "Exception: e-mail or token undef"
60 unless $self->email && $self->token;
61  
62 # manual instance
63 $self->{_transaction} = $_[0]
64 if $_[0] && $_[0]->isa('PagSeguro::API::Transaction');
65  
66  
67 $self->{_transaction} = PagSeguro::API::Transaction->new(
68 email => $self->email, token => $self->token
69 ) unless $self->{_transaction};
70  
71 return $self->{_transaction};
72 }
73  
74 sub notification {
75 my $self = shift;
76  
77 # error
78 die "Exception: e-mail or token undef"
79 unless $self->email && $self->token;
80  
81 # manual instance
82 $self->{_notification} = $_[0]
83 if $_[0] && $_[0]->isa('PagSeguro::API::Notification');
84  
85  
86 $self->{_notification} = PagSeguro::API::Notification->new(
87 email => $self->email, token => $self->token
88 ) unless $self->{_notification};
89  
90 return $self->{_notification};
91 }
92  
93 sub checkout {
94 my $self = shift;
95  
96 # error
97 die "Exception: e-mail or token undef"
98 unless $self->email && $self->token;
99  
100 # manual instance
101 $self->{_checkout} = $_[0]
102 if $_[0] && $_[0]->isa('PagSeguro::API::Checkout');
103  
104  
105 $self->{_checkout} = PagSeguro::API::Checkout->new(
106 email => $self->email, token => $self->token
107 ) unless $self->{_checkout};
108  
109 return $self->{_checkout};
110 }
111  
112  
113 1;
114 __END__