| 1 | package Weather::Bug::Station; | ||||||||||||||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Weather::Bug::Location; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Weather::Bug::Temperature; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Weather::Bug::Quantity; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use Weather::Bug::CompactWeather; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | ▶ | use Weather::Bug::Weather; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | our $VERSION = '0.25'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | has 'id' => ( is => 'ro', isa => 'Str', init_arg => '-id' ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | has 'name' => ( is => 'ro', isa => 'Str', init_arg => '-name' ); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | has 'url' => ( is => 'ro', isa => 'Str', init_arg => '-url', predicate => 'has_url' ); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | has 'location' => ( is => 'ro', isa => 'Weather::Bug::Location', init_arg => '-loc' ); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 12 | has 'station_type' => ( is => 'ro', isa => 'Str', init_arg => '-type' ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | has 'bug' => ( is => 'ro', isa => 'Weather::Bug', init_arg => '-bug' ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub from_xml | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 100 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_xml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 100 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 100 | my $bug = shift; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 100 | my $statnode = shift; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 100 | return Weather::Bug::Station->new( | |||||||||||||||||||||||||||||||||||||||||
| 30 | -id => $statnode->findvalue( '@id' ), | ||||||||||||||||||||||||||||||||||||||||||
| 31 | -name => $statnode->findvalue( '@name' ), | ||||||||||||||||||||||||||||||||||||||||||
| 32 | -loc => Weather::Bug::Location->from_station_xml( $statnode ), | ||||||||||||||||||||||||||||||||||||||||||
| 33 | -type => $statnode->findvalue( '@station-type' ), | ||||||||||||||||||||||||||||||||||||||||||
| 34 | -bug => $bug, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | sub from_compact_xml | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_compact_xml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $bug = shift; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my $statnode = shift; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | return Weather::Bug::Station->new( | |||||||||||||||||||||||||||||||||||||||||
| 45 | -id => $statnode->findvalue( '@id' ), | ||||||||||||||||||||||||||||||||||||||||||
| 46 | -name => $statnode->findvalue( '@name' ), | ||||||||||||||||||||||||||||||||||||||||||
| 47 | -loc => Weather::Bug::Location->from_compact_station_xml( $statnode ), | ||||||||||||||||||||||||||||||||||||||||||
| 48 | -type => $statnode->findvalue( '@station-type' ), | ||||||||||||||||||||||||||||||||||||||||||
| 49 | -bug => $bug, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | sub from_obs_xml | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_obs_xml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | my $bug = shift; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | return Weather::Bug::Station->new( | |||||||||||||||||||||||||||||||||||||||||
| 60 | -id => $node->findvalue( 'aws:station-id' ), | ||||||||||||||||||||||||||||||||||||||||||
| 61 | -name => $node->findvalue( 'aws:station' ), | ||||||||||||||||||||||||||||||||||||||||||
| 62 | -loc => Weather::Bug::Location->from_obs_xml( ($node->findnodes( 'aws:city-state' ))[0] ), | ||||||||||||||||||||||||||||||||||||||||||
| 63 | -url => $node->findvalue( 'aws:site-url' ), | ||||||||||||||||||||||||||||||||||||||||||
| 64 | -bug => $bug, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # Utility method that simplifies calling the WeatherBug::request method for | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # the API requests associated with the Station object. | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # $cmd - command name | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # Returns the XML response as a string if successful, or C<undef> on failure. | ||||||||||||||||||||||||||||||||||||||||||
| 75 | sub _request | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_request: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | my $cmd = shift; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | return $self->{bug}->request( | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | $cmd, { zipcode => $self->location()->zipcode, | |||||||||||||||||||||||||||||||||||||||||
| 82 | StationId => $self->id } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | sub is_equivalent | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_equivalent: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $other = shift; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return unless $other->isa( __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return unless $self->id() eq $other->id(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return unless $self->name() eq $other->name(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return unless $self->station_type() eq $other->tation_type(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return if $self->has_url() and $other->has_url and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->has_url and $other->has_url and $self->url ne $other->url
$self->has_url and $other->has_url
MC/DC0%0/3
$self->has_url and $other->has_url and $self->url ne $other->url
$self->has_url
$other->has_url
$self->url ne $other->url
Truth table0%0/4
A and B and C
A= $self->has_urlB= $other->has_urlC= $self->url ne $other->url
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | $self->url() ne $other->url(); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return $self->location()->is_equivalent( $other->location() ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | sub get_live_weather | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_live_weather: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $response = $self->_request( 'getLiveWeather' ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | my $p = XML::LibXML->new(); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | my $doc = $p->parse_string( $response ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | my ($ob) = $doc->findnodes( '//aws:ob' ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | return Weather::Bug::Weather->from_xml( $ob, $self ); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | sub get_live_compact_weather | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_live_compact_weather: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | my $response = $self->_request( 'getLiveCompactWeather' ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | my $p = XML::LibXML->new(); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | my $doc = $p->parse_string( $response ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | my ($w) = $doc->findnodes( '//aws:weather' ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | return Weather::Bug::CompactWeather->from_xml( $w, $self ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 12 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||||||||||||||||
| 124 | __END__ | ||||||||||||||||||||||||||||||||||||||||||