| 1 | package Finance::Currency::Convert::Custom; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use base qw(Finance::Currency::Convert); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | our $VERSION = '1.00'; | |||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | sub updateRates() { | ||||||||||
| 11 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
updateRates: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||
| 12 | 0 | my $sub_ref = shift; | |||||||||
| 13 | |||||||||||
| 14 | 0 | my @CurrencyList = @_; | |||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | unless(ref $sub_ref eq 'CODE'){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | #case of not defined own sub and sent countries list as params :) | ||||||||||
| 18 | 0 | ▶ | unless(ref $sub_ref){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | push @CurrencyList, $sub_ref; | |||||||||
| 20 | } | ||||||||||
| 21 | 0 | ▶ | $sub_ref = sub{my ($cur_from, $cur_to) = @_; return $self->currency_finyahoo($cur_from, $cur_to);} | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 22 | 0 | } | |||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | 0 | foreach my $source (@CurrencyList) { | |||||||||
| 26 | 0 | foreach my $target (sort keys %{ $self->{CurrencyRates}}) { | |||||||||
| 27 | 0 | $self->setRate($source, $target, &{$sub_ref}($source, $target)); | |||||||||
| 28 | } | ||||||||||
| 29 | } | ||||||||||
| 30 | 0 | foreach my $source (sort keys %{ $self->{CurrencyRates}}) { | |||||||||
| 31 | 0 | foreach my $target (@CurrencyList) { | |||||||||
| 32 | 0 | $self->setRate($source, $target, &{$sub_ref}($source, $target)); | |||||||||
| 33 | } | ||||||||||
| 34 | } | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | sub updateRate() { | ||||||||||
| 38 | 12 | ▶ | my $self = shift; | ||||||||
|
Subroutine
updateRate: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 39 | 12 | my $sub_ref = shift; | |||||||||
| 40 | 12 | my $source = shift; | |||||||||
| 41 | 12 | my $target = shift; | |||||||||
| 42 | 12 | ▶ | unless(ref $sub_ref eq 'CODE'){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | #case of not defined own sub and sent countries list as params :) | ||||||||||
| 44 | 12 | ▶ | unless(ref $sub_ref){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 12 | $target = $source; | |||||||||
| 46 | 12 | $source = $sub_ref; | |||||||||
| 47 | } | ||||||||||
| 48 | 12 | ▶ | $sub_ref = sub{my ($cur_from, $cur_to) = @_; return $self->currency_finyahoo($cur_from, $cur_to);} | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 12 | } | |||||||||
| 50 | |||||||||||
| 51 | 12 | $self->setRate($source, $target, &{$sub_ref}($source, $target)); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | sub currency_finyahoo() { | ||||||||||
| 61 | |||||||||||
| 62 | 12 | ▶ | my $self = shift; | ||||||||
|
Subroutine
currency_finyahoo: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 63 | #$self->{UserAgent} | ||||||||||
| 64 | 12 | my ($cur_from, $cur_to) = @_; | |||||||||
| 65 | 12 | my $browser = LWP::UserAgent->new; | |||||||||
| 66 | 12 | my $response = $browser->get( "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=".$cur_from.$cur_to."=X" ); | |||||||||
| 67 | 12 | my $data = $response->content(); | |||||||||
| 68 | 12 | my @arr = split /,/,$data; | |||||||||
| 69 | 12 | return $arr[1]; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | 1 | 1; | |||||||||
| 76 | |||||||||||
| 77 | __END__ | ||||||||||