Primitive/Way.pm

filter: Statementstmt 56.2% 18 / 32 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 3 / 3 totaltotal 56.5% 26 / 46 CC 2 SCAR 8.3
CC
2
Cov
53%
new
6.0
nodes
2.0
start_end_coordinates
2.0
CRAP 2.3
« Primitive/Node.pm ↑ Summary
1 # Encoding and name #_{
2  
3 =encoding utf8
4 =head1 NAME
5  
6 Geo::OSM::Primitive::Way - Abstract base class for the Open Street Map data primitive I<way>.
7  
8 =cut
9 package Geo::OSM::Primitive::Way;
10 1 our @ISA = qw(Geo::OSM::Primitive);
11 #_}
12 #_{ use …
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Geo::OSM::Primitive;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #_}
21 1 our $VERSION = 0.01;
22 #_{ Synopsis
23  
24 =head1 SYNOPSIS
25  
26 …
27  
28 =cut
29 #_}
30 #_{ Overview
31  
32 =head1 OVERVIEW
33  
34 The idea is to encapsulte methods that use OpenStreetMap data (that is possibly stored in L<Geo::OSM::DBI>.
35  
36 =cut
37  
38 #_}
39 #_{ Methods
40  
41 =head1 METHODS
42 =cut
43  
44 0 ▶sub new { #_{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
45 #_{ POD
46  
47 =head2 new
48  
49 my $way = Geo::OSM::Primitive::Way->new($osm_way_id);
50  
51 =cut
52  
53 #_}
54  
55 0 my $class = shift;
56 0 my $id = shift;
57  
58 0 my $self = $class->SUPER::new($id, 'way');
59 0 ▶ croak "Wrong class $class" unless $self->isa('Geo::OSM::Primitive::Way');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isa("Geo::OSM::Primitive::Way") 0 0 0
60  
61 0 $self->{nodes} = [];
62  
63 0 return $self;
64  
65 } #_}
66 0 ▶sub nodes { #_{
Subroutine nodes: not called CC=1 SCAR=6.9
Pod documented
67 #_{ POD
68  
69 =head2 nodes
70  
71 my @nodes = $way -> nodes();
72  
73 Returns the nodes, stored in the cache via L</_set_cache_nodes>, that the way conisist of.
74  
75 =cut
76  
77 #_}
78  
79 0 my $self = shift;
80  
81 0 return @{$self->{cache}->{nodes}};
82  
83 } #_}
84 0 ▶sub start_end_coordinates { #_{
Subroutine start_end_coordinates: not called CC=1 SCAR=6.9
Pod documented
85 #_{ POD
86  
87 =head2 start_end_coordinates
88  
89 my ($lat_start, $lon_start, $lat_end, $lon_end) = $way -> start_end_coordinates();
90  
91 Returns the way's start and end coordinates.
92  
93 =cut
94  
95 #_}
96  
97 0 my $self = shift;
98 0 my @nodes = $self->nodes;
99  
100 0 return ($nodes[0]->lat, $nodes[0]->lon, $nodes[-1]->lat, $nodes[-1]->lon);
101  
102 } #_}
103 0 ▶sub _set_cache_nodes { #_{
Subroutine _set_cache_nodes: not called CC=1 SCAR=6.9
104 #_{ POD
105  
106 =head2 _set_cache_nodes
107  
108 $way->_set_cache_nodes($node_1, $node_2, $node_3, … $node_n);
109  
110 =cut
111  
112 #_}
113
114 0 my $self = shift;
115 0 $self->{cache}->{nodes} = \@_;
116  
117 } #_}
118 # sub add_node { #_{
119 # #_{ POD
120 #
121 # =head2 add_node
122 #
123 # my $node = Geo::OSM::Primitive::Node->new($osm_node_id …);
124 # my $way = Geo::OSM::Primitive::Way ->new($osm_way_id …);
125 #
126 # $way->add_node($node);
127 #
128 # =cut
129 #
130 # #_}
131 #
132 # my $self = shift;
133 # my $node = shift;
134 #
135 # croak "$node is not a Geo::OSM::Primitive::Node" unless $node->isa($node);
136 # push @{$self->{nodes}}, $node;
137 #
138 # } #_}
139 # sub cnt_nodes { #_{
140 # #_{ POD
141 #
142 # =head2 cnt_nodes
143 #
144 # my $cnt_nodes_in_way = $way->cnt_nodes();
145 #
146 # =cut
147 #
148 # #_}
149 #
150 # my $self = shift;
151 #
152 # return scalar @{$self->{nodes}}
153 #
154 # } #_}
155  
156 #_}
157 #_{ POD: Copyright
158  
159 =head1 Copyright
160 Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved.
161 This program is free software; you can redistribute it and/or modify it
162 under the terms of the the Artistic License (2.0). You may obtain a
163 copy of the full license at: L<http://www.perlfoundation.org/artistic_license_2_0>
164 =cut
165  
166 #_}
167 #_{ POD: Source Code
168  
169 =head1 Source Code
170  
171 The source code is on L<< github|https://github.com/ReneNyffenegger/perl-Geo-OSM-Primitive >>. Meaningful pull requests are welcome.
172  
173 =cut
174  
175 #_}
176  
177 1 'tq84';
« Primitive/Node.pm ↑ Summary