Bug/SevenDayForecast.pm

filter: Statementstmt 100% 45 / 45 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 96.7% 59 / 61 CC 4 SCAR 4.6
CC
4
Cov
96%
_parse_forecast_list
3.0
_parse_date
2.0
BEGIN
1.0
CRAP 1.6
« Bug/CompactWeather.pm ↑ Summary Bug/Alert.pm »
1 package Weather::Bug::SevenDayForecast;
2  
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Weather::Bug::Location;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Weather::Bug::Forecast;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Weather::Bug::DateParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 our $VERSION = '0.25';
13  
14 12 has 'type' => ( is => 'ro', isa => 'Str', init_arg => '-type' );
15 12 has 'date' => ( is => 'ro', isa => 'DateTime', init_arg => '-date' );
16 12 has 'location' => ( is => 'ro', isa => 'Weather::Bug::Location', init_arg => '-loc' );
17 12 has 'forecasts' => ( is => 'ro', isa => 'ArrayRef[Weather::Bug::Forecast]', init_arg => '-forecasts' );
18  
19 sub _parse_date
20 3 ▶{
Subroutine _parse_date: called CC=2 SCAR=7.0
21 3 my $date_str = shift;
22  
23 3 my $d = eval {
24 3 my $p = Weather::Bug::DateParser->new();
25 3 $p->parse_datetime( $date_str );
26 };
27 3 ▶ die "Date string is not formatted as expected.\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
28 3 return $d;
29 }
30  
31 sub from_xml
32 3 ▶{
Subroutine from_xml: called CC=1 SCAR=0.0
Pod documented
33 3 my $class = shift;
34 3 my $node = shift;
35  
36 3 return Weather::Bug::SevenDayForecast->new(
37 -type => $node->findvalue( '@type' ),
38 -date => _parse_date( $node->findvalue( '@date' ) ),
39 -loc => Weather::Bug::Location->from_forecast( ($node->findnodes( "aws:location" ))[0] ),
40 -forecasts => _parse_forecast_list( $node->findnodes( 'aws:forecast' ) ),
41 );
42 }
43  
44 sub _parse_forecast_list
45 3 ▶{
Subroutine _parse_forecast_list: called CC=3 SCAR=11.0
46 3 my @fcnodes = @_;
47 3 my @forecasts = ();
48  
49 3 ▶ die "No 'aws:forecast' nodes found.\n" unless @fcnodes;
Branch: 1 branch
BranchTrueFalseTotal
unless @fcnodes 0 3 3
50  
51 3 foreach my $fcast (@fcnodes)
52 {
53 39 push @forecasts,
54 Weather::Bug::Forecast->from_xml( $fcast );
55 }
56 3 return \@forecasts;
57 }
58  
59 12 1; # Magic true value required at end of module
60 __END__
« Bug/CompactWeather.pm ↑ Summary Bug/Alert.pm »