Class/LivedoorWeather.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 55 CC 4 SCAR 23.0
CC
4
Cov
0%
load_city_id
20.0
init
2.0
weather
2.0
CRAP 10.0
1 package WebService::Class::LivedoorWeather;
2 use strict;
3 use base qw(WebService::Class::AbstractHTTPRequestClass);
4 use utf8;
5 binmode STDOUT, ":utf8";
6 __PACKAGE__->mk_accessors(qw(city));
7 __PACKAGE__->mk_classdata('define_city' =>'http://weather.livedoor.com/forecast/rss/forecastmap.xml');
8 __PACKAGE__->base_url('http://weather.livedoor.com/forecast/webservice/rest/v1');
9  
10 sub init{
11 my $self = shift;
12 $self->SUPER::init(@_);
13 $self->load_city_id;
14 }
15  
16 sub load_city_id{
17 my $self = shift;
18
19 my $result = $self->request_api()->request('GET',$self->define_city,{})->parse_xml();
20 $self->city({});
21 foreach my $area (@{$result->{channel}->{"ldWeather:source"}->{area}}){
22 my ($area_id) = ($area->{source} =~ /([0-9]*)\.xml/);
23 print $area_id;
24 if(ref $area->{pref} eq "ARRAY"){
25 foreach my $pref (@{$area->{pref}}){
26 my ($pref_id) = ($pref->{warn}->{source} =~ /([a-z]*)\.xml/);
27 print $pref_id;
28 if(ref $pref->{city} eq "HASH"){
29 if(exists $pref->{city}->{source}){
30 $self->city->{$pref->{city}->{id}} = $pref->{city}->{title};
31 }
32 else{
33 foreach my $key (keys %{$pref->{city}}){
34 $self->city->{$key} = $pref->{city}->{$key}->{title};
35 }
36 }
37 }
38 }
39 }
40 }
41 }
42  
43 sub weather{
44 my $self = shift;
45 my $city = shift;
46 my $day = shift;
47 return $self->request_api()->request('GET',$self->define_city,{'city'=>$city,'day'=>$day})->parse_xml();
48 }
49  
50