File Coverage

blib/lib/Paymill/REST/TypesAndTriggers.pm
Criterion Covered Total %
statement 9 22 40.9
branch 0 4 0.0
condition 0 6 0.0
subroutine 3 5 60.0
pod 0 2 0.0
total 12 39 30.7


line stmt bran cond sub pod time code
1             package Paymill::REST::TypesAndTriggers;
2              
3 9     9   4841 use Moose;
  9         25  
  9         135  
4 9     9   65561 use Moose::Util::TypeConstraints;
  9         21  
  9         93  
5              
6             enum 'CCorDebit', [qw/creditcard debit/];
7             enum 'TxStatus', [qw/open pending closed failed partial_refunded refunded preauth chargeback/];
8             enum 'RefundStatus', [qw/open refunded failed/];
9             enum 'PreauthStatus', [qw/open pending closed failed deleted preauth/];
10              
11             sub item_from_hashref {
12 0     0 0   my ($type, $self, $new_value, $old_value) = @_;
13              
14 0 0 0       unless (blessed $new_value || ref $new_value ne 'HASH') {
15 0           my $item_class = 'Paymill::REST::Item::' . ucfirst($type);
16              
17 0           (ref $self)->meta->get_attribute($type)
18             ->set_raw_value($self, $item_class->new(%$new_value, _factory => $self->_factory));
19             }
20             }
21              
22             sub items_from_arrayref {
23 0     0 0   my ($type, $self, $new_value, $old_value) = @_;
24              
25 0           (my $singular_type = $type) =~ s/s$//;
26              
27 0 0 0       unless (blessed $new_value->[0] || ref $new_value->[0] ne 'HASH') {
28 0           my $item_class = 'Paymill::REST::Item::' . ucfirst($singular_type);
29              
30 0           my $raw_value = [];
31 0           foreach (@$new_value) {
32 0           push @$raw_value, $item_class->new(%{ $new_value->[0] }, _factory => $self->_factory);
  0            
33             }
34              
35 0           (ref $self)->meta->get_attribute($type)->set_raw_value($self, $raw_value);
36             }
37             }
38              
39 9     9   23725 no Moose::Util::TypeConstraints;
  9         24  
  9         66  
40             1;
41             __END__
42              
43             =encoding utf-8
44              
45             =head1 NAME
46              
47             Paymill::REST::TypesAndTriggers - Helper class
48              
49             =head1 DESCRIPTION
50              
51             Helper class defining types and triggers used internally for item's attributes.
52              
53             =head1 SEE ALSO
54              
55             L<Paymill::REST> for documentation.
56              
57             =head1 AUTHOR
58              
59             Matthias Dietrich E<lt>perl@rainboxx.deE<gt>
60              
61             =head1 COPYRIGHT
62              
63             Copyright 2013 - Matthias Dietrich
64              
65             =head1 LICENSE
66              
67             This library is free software; you can redistribute it and/or modify
68             it under the same terms as Perl itself.