File Coverage

blib/lib/Data/Money/Converter/WebserviceX.pm
Criterion Covered Total %
statement 15 19 78.9
branch 0 2 0.0
condition n/a
subroutine 5 7 71.4
pod 1 1 100.0
total 21 29 72.4


line stmt bran cond sub pod time code
1             package Data::Money::Converter::WebserviceX;
2              
3             $Data::Money::Converter::WebserviceX::VERSION = '0.06';
4             $Data::Money::Converter::WebserviceX::AUTHORITY = 'gphat';
5              
6             =head1 NAME
7              
8             Data::Money::Converter::WebserviceX - WebserviceX currency conversion implementation.
9              
10             =head1 VERSION
11              
12             Version v0.06
13              
14             =head1 SYNOPSIS
15              
16             use strict; use warnings;
17             use Data::Money;
18             use Data::Money::Converter::WebserviceX;
19              
20             my $curr = Data::Money->new(value => 10, code => 'USD');
21             my $conv = Data::Money::Converter::WebserviceX->new;
22             my $newc = $conv->convert($curr, 'GBP');
23              
24             print $newc->value, "\n";
25              
26             =cut
27              
28 2     2   235972 use Moo;
  2         11772  
  2         14  
29 2     2   2080 use namespace::clean;
  2         10201  
  2         17  
30              
31 2     2   1221 use Data::Dumper;
  2         10858  
  2         184  
32 2     2   653 use Locale::Currency;
  2         21665  
  2         185  
33 2     2   1562 use Finance::Currency::Convert::WebserviceX;
  2         114575  
  2         519  
34              
35             with 'Data::Money::Converter';
36              
37             has '_converter' => (is => 'lazy');
38             has 'valid_currency_code' => (is => 'ro', default => sub {
39             return {
40             map { uc($_) => uc($_) } Locale::Currency::all_currency_codes()
41             };
42             });
43              
44             sub _build__converter {
45 0     0     return Finance::Currency::Convert::WebserviceX->new;
46             }
47              
48             =head1 METHODS
49              
50             =head2 convert($money, $code)
51              
52             Convert C<$money>, which is an object of type L to currency C<$code>
53             and returns an object of type L.The C<$code> has to be a valid three
54             letter codes.
55              
56             =cut
57              
58             sub convert {
59 0     0 1   my ($self, $curr, $code) = @_;
60              
61             #die "[$code]",Dumper($self->{valid_currency_code});
62             die "ERROR: $code is not a valid currency code.\n"
63 0 0         unless ($self->{valid_currency_code}{uc($code)});
64              
65 0           return $curr->clone(
66             code => $code,
67             value => $self->_converter->convert($curr->value, $curr->code, $code),
68             );
69             }
70              
71             =head1 AUTHOR
72              
73             Cory G Watson, C<< >>
74              
75             Currently maintained by Mohammad S Anwar (MANWAR) C<< >>
76              
77             =head1 REPOSITORY
78              
79             L
80              
81             =head1 SEE ALSO
82              
83             =over 4
84              
85             =item L
86              
87             =item L
88              
89             =back
90              
91             =head1 COPYRIGHT & LICENSE
92              
93             Copyright 2010 Cory G Watson.
94              
95             This program is free software; you can redistribute it and/or modify it under the
96             terms of either: the GNU General Public License as published by the Free Software
97             Foundation; or the Artistic License.
98              
99             See http://dev.perl.org/licenses/ for more information.
100              
101             =cut
102              
103             1; # End of Data::Money::Converter::WebserviceX