OpenGbg/Service/StyrOchStall/GetBikeStations.pm

filter: Statementstmt 86.4% 32 / 37 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 100% 1 / 1 totaltotal 83.6% 41 / 49 CC 1 SCAR 2.4
CC
1
Cov
86%
get_by_id
2.0
__ANON__
2.0
_build_timestamp
2.0
CRAP 1.3
« OpenGbg/Service/Bridge.pm ↑ Summary OpenGbg/Service/AirQuality.pm »
1 7 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package OpenGbg::Service::StyrOchStall::GetBikeStations;
6  
7 # ABSTRACT: Get data on all bike stations
8 7 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 7 our $VERSION = '0.1401';
10  
11 7 ▶use XML::Rabbit::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use DateTime::Format::HTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use MooseX::AttributeShortcuts;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use Types::Standard qw/Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use Types::DateTime qw/DateTime/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 7 has xml => (
18 is => 'ro',
19 isa => Str,
20 required => 1,
21 );
22  
23 7 add_xpath_namespace 'x' => 'TK.DevServer.Services.RentalBikeService';
24  
25 7 has_xpath_value _timestamp => '/x:RentalBikes/x:TimeStamp';
26  
27 7 has_xpath_object_list stations => '/x:RentalBikes/x:Stations/x:Details' => 'OpenGbg::Service::StyrOchStall::Station',
28 handles => {
29 all => 'elements',
30 count => 'count',
31 filter => 'grep',
32 find => 'first',
33 get_by_index => 'get',
34 map => 'map',
35 sort => 'sort',
36 };
37  
38 sub get_by_id {
39 0 ▶ my $self = shift;
Subroutine get_by_id: not called CC=1 SCAR=6.9
Pod documented
40 0 my $id = shift;
41  
42 0 ▶ return $self->find(sub { $_->id == $id });
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 }
44  
45 7 has timestamp => (
46 is => 'ro',
47 isa => DateTime,
48 lazy => 1,
49 builder => 1,
50 );
51  
52 sub _build_timestamp {
53 0 ▶ return DateTime::Format::HTTP->parse_datetime(shift->_timestamp);
Subroutine _build_timestamp: not called CC=1 SCAR=6.9
54 }
55  
56 7 finalize_class();
57  
58 7 1;
59  
60 __END__
61  
62 =pod
63  
64 =encoding utf-8
65  
66 =head1 NAME
67  
68 OpenGbg::Service::StyrOchStall::GetBikeStations - Get data on all bike stations
69  
70 =head1 VERSION
71  
72 Version 0.1401, released 2016-05-05.
73  
74 =head1 SYNOPSIS
75  
76 my $service = OpenGbg->new->styr_och_stall;
77 my $stations = $service->get_bike_stations;
78  
79 printf 'Time: %s', $stations->timestamp;
80 print $stations->get_by_index(5)->to_text;
81  
82 =head1 METHODS
83  
84 =head2 timestamp
85  
86 Returns the timestamp given in the response as a L<DateTime> object.
87  
88 =head2 all
89  
90 Returns an array of the L<OpenGbg::Service::StyrOchStall::Station> objects in the response.
91  
92 =head2 count
93  
94 Returns the number of L<Station|OpenGbg::Service::StyrOchStall::Station> objects in the response.
95  
96 =head2 filter(sub { ... })
97  
98 Allows filtering of the stations. Takes a sub routine reference, into which all L<Station|OpenGbg::Service::StyrOchStall::Station> objects are
99 passed one-by-one into C<$_>. Works like C<grep>.
100  
101 =head2 find(sub { ... })
102  
103 Just like C<filter>, except it returns the first station that matches.
104  
105 =head2 get_by_index($index)
106  
107 Returns the n:th L<OpenGbg::Service::StyrOchStall::Station> object in the response.
108  
109 =head2 get_by_id($id)
110  
111 Returns the station with id C<$id>.
112  
113 =head2 map(sub { ... })
114  
115 Like C<filter> it takes a sub routine reference and passes each L<Station|OpenGbg::Service::StyrOchStall::Station> as C<$_>. Eg, to get a total count of free bikes:
116  
117 use List::AllUtils 'sum';
118 my $free_bikes_count = sum $response->stations->map( sub { $_->free_bikes });
119  
120 =head2 sort(sub { ... })
121  
122 Like C<filter> it takes a sub routine reference. It works just like C<sort> except the two L<Station|OpenGbg::Service::StyrOchStall::Station> objects to compare are passed as C<$_[0]> and C<$_[1]>
123  
124 my @most_bikes_first = $response->stations->sort( sub { $_[1]->free_bikes <=> $_[0]->free_bikes });
125  
126 =head1 SOURCE
127  
128 L<https://github.com/Csson/p5-OpenGbg>
129  
130 =head1 HOMEPAGE
131  
132 L<https://metacpan.org/release/OpenGbg>
133  
134 =head1 AUTHOR
135  
136 Erik Carlsson <info@code301.com>
137  
138 =head1 COPYRIGHT AND LICENSE
139  
140 This software is copyright (c) 2016 by Erik Carlsson.
141  
142 This is free software; you can redistribute it and/or modify it under
143 the same terms as the Perl 5 programming language system itself.
144  
145 =cut
« OpenGbg/Service/Bridge.pm ↑ Summary OpenGbg/Service/AirQuality.pm »