OpenGbg/Service/Bridge/BridgeOpenings.pm

filter: Statementstmt 100% 16 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 20 / 20 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« OpenGbg/Service/AirQuality/Measurements.pm ↑ Summary OpenGbg/Service/Bridge/GetOpenedStatus.pm »
1 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package OpenGbg::Service::Bridge::BridgeOpenings;
6  
7 # ABSTRACT: A list of bridge openings/closings
8 1 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 1 our $VERSION = '0.1401';
10  
11 1 ▶use XML::Rabbit;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 has_xpath_object_list _bridge_openings => './x:BridgeOpen' => 'OpenGbg::Service::Bridge::BridgeOpening',
14 handles => {
15 all => 'elements',
16 count => 'count',
17 filter => 'grep',
18 find => 'first',
19 get_by_index => 'get',
20 map => 'map',
21 sort => 'sort',
22 };
23  
24 1 finalize_class();
25  
26 1 1;
27  
28 __END__
29  
30 =pod
31  
32 =encoding utf-8
33  
34 =head1 NAME
35  
36 OpenGbg::Service::Bridge::BridgeOpenings - A list of bridge openings/closings
37  
38 =head1 VERSION
39  
40 Version 0.1401, released 2016-05-05.
41  
42 =head1 SYNOPSIS
43  
44 my $bridge = OpenGbg->new->bridge;
45 my $get_os = $bridge->get_opened_status;
46  
47 my $opening = $get_opened_status->bridge_openings->get_by_index(5);
48  
49 printf 'It was %s at %s on %s', $opening->was_open ? 'open' : 'closed', $opening->timestamp->hms, $opening->timestamp->ymd;
50  
51 =head1 METHODS
52  
53 =head2 all
54  
55 Returns an array of the L<OpenGbg::Service::Bridge::BridgeOpening> objects in the response.
56  
57 =head2 count
58  
59 Returns the number of L<BridgeOpening|OpenGbg::Service::Bridge::BridgeOpening> objects in the response.
60  
61 =head2 filter(sub { ... })
62  
63 Allows filtering of the bridge openings. Takes a sub routine reference, into which all L<BridgeOpening|OpenGbg::Service::Bridge::BridgeOpening> objects are
64 passed one-by-one into C<$_>. Works like C<grep>. For example, to get the number of times the bridge was open:
65  
66 use List::AllUtils 'sum';
67 my $opening_count = scalar $get_opened_status->bridge_openings->filter(sub { $_->was_open });
68  
69 =head2 find(sub { ... })
70  
71 Just like C<filter>, except it returns the first bridge opening that matches.
72  
73 =head2 get_by_index($index)
74  
75 Returns the n:th L<OpenGbg::Service::Bridge::BridgeOpening> object in the response.
76  
77 =head2 map(sub { ... })
78  
79 Like C<filter> it takes a sub routine reference and passes each L<BridgeOpening|OpenGbg::Service::Bridge::BridgeOpening> as C<$_>.
80  
81 =head2 sort(sub { ... })
82  
83 Like C<filter> it takes a sub routine reference. It works just like C<sort> except the two L<BridgeOpening|OpenGbg::Service::Bridge::BridgeOpening> objects to compare are passed as C<$_[0]> and C<$_[1]>
84  
85 =head1 SOURCE
86  
87 L<https://github.com/Csson/p5-OpenGbg>
88  
89 =head1 HOMEPAGE
90  
91 L<https://metacpan.org/release/OpenGbg>
92  
93 =head1 AUTHOR
94  
95 Erik Carlsson <info@code301.com>
96  
97 =head1 COPYRIGHT AND LICENSE
98  
99 This software is copyright (c) 2016 by Erik Carlsson.
100  
101 This is free software; you can redistribute it and/or modify it under
102 the same terms as the Perl 5 programming language system itself.
103  
104 =cut
« OpenGbg/Service/AirQuality/Measurements.pm ↑ Summary OpenGbg/Service/Bridge/GetOpenedStatus.pm »