MapFeatures/Feature/Value.pm

filter: Statementstmt 46.3% 25 / 54 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 55.5% 5 / 9 Podpod 25.0% 1 / 4 totaltotal 27.4% 31 / 113 CC 17 SCAR 49.8
CC
17
Cov
27%
new
240.0
init
6.0
compare
6.0
CRAP 145.2
↑ Summary MapFeatures/Feature.pm »
1 package Geo::OSM::MapFeatures::Feature::Value;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use base qw( Class::Factory Class::Accessor );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 __PACKAGE__->mk_accessors(qw(value));
10  
11 2 ▶use overload '""' => \&stringify, '<=>' => \&compare, 'cmp' => \&compare;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 Geo::OSM::MapFeatures::Feature::Value - Represents a feature value
16  
17 =head1 VERSION
18  
19 Version 0.01
20  
21 =cut
22  
23 2 our $VERSION = '0.01';
24  
25  
26 =head1 SYNOPSIS
27  
28 This module represents a value on a feature from map features.
29  
30 To handle all the special value types this class is a factory and returns
31 a subclass of itself if the value is special. Normal static strings are
32 handled in this module.
33  
34 =cut
35  
36 2 __PACKAGE__->add_factory_type( userdef => "Geo::OSM::MapFeatures::Feature::Value::Userdef" );
37 2 __PACKAGE__->add_factory_type( num => "Geo::OSM::MapFeatures::Feature::Value::Num" );
38 2 __PACKAGE__->add_factory_type( range => "Geo::OSM::MapFeatures::Feature::Value::Range" );
39 2 __PACKAGE__->add_factory_type( date => "Geo::OSM::MapFeatures::Feature::Value::Date" );
40 2 __PACKAGE__->add_factory_type( time => "Geo::OSM::MapFeatures::Feature::Value::Time" );
41 2 __PACKAGE__->add_factory_type( list => "Geo::OSM::MapFeatures::Feature::Value::List" );
42 2 __PACKAGE__->add_factory_type( numwithunit => "Geo::OSM::MapFeatures::Feature::Value::NumWithUnit" );
43  
44 =head1 FUNCTIONS
45  
46 =head2 value
47  
48 This always contains the value as it was on map features (except any
49 wiki syntax)
50  
51 =cut
52  
53 0 ▶sub new {
Subroutine new: not called CC=15 SCAR=54.8
Pod documented
54 0 my $pkg = shift;
55 0 my $value = shift();
56  
57 0 ▶ my $class = ref($pkg) || $pkg;
Condition0%0/3
ref $pkg || $pkg
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table0%0/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
58 0 my %classargs;
59  
60 # Arbitrarily defined value
61 0 ▶ if( $value =~ /user defined|defined by editor/i || $value =~ /^\s*\.\.\.\s*$/ ){
Branch: 9 branches
BranchTrueFalseTotal
if ($value =~ /user defined|defined by editor/i or $value =~ /^\s*\.\.\.\s*$/) { } 0 0 0
elsif ($value eq '') { } 0 0 0
elsif (lc $value eq 'num' or lc $value eq 'number') { } 0 0 0
elsif ($value =~ /^(-?\d+)\s+to\s+(-?\d+)$/i) { } 0 0 0
elsif (lc $value eq 'date') { } 0 0 0
elsif (lc $value eq 'day of week') { } 0 0 0
elsif (lc $value eq 'time') { } 0 0 0
elsif (lc $value eq 'speed') { } 0 0 0
elsif (lc $value eq 'length' or lc $value eq 'height' or lc $value eq 'width') { } 0 0 0
Condition0%0/3
$value =~ /user defined|defined by editor/i or $value =~ /^\s*\.\.\.\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$value =~ /user defined|defined by editor/i or $value =~ /^\s*\.\.\.\s*$/
$value =~ /user defined|defined by editor/i $value =~ /^\s*\.\.\.\s*$/
Truth table0%0/3
A or B
A= $value =~ /user defined|defined by editor/iB= $value =~ /^\s*\.\.\.\s*$/
ABresult
1X1
011
000
62 #FIXME: Maybe defined by editor should be separate?
63 0 $class = $pkg->get_factory_class('userdef');
64 }
65 # Empty value - what the heck?
66 elsif( $value eq '' ){
67 0 Carp::carp "Empty value, what the heck? Calling it user defined";
68 0 $class = $pkg->get_factory_class('userdef');
69 }
70 # Numeric value
71 ▶ elsif( lc($value) eq 'num' || lc($value) eq 'number' ){
Condition0%0/3
lc $value eq "num" or lc $value eq "number"
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $value eq "num" or lc $value eq "number"
lc $value eq "num" lc $value eq "number"
Truth table0%0/3
A or B
A= lc $value eq "num"B= lc $value eq "number"
ABresult
1X1
011
000
72 0 $class = $pkg->get_factory_class('num');
73 }
74 # Range value
75 elsif( $value =~ /^(-?\d+)\s+to\s+(-?\d+)$/i ){
76 0 $class = $pkg->get_factory_class('range');
77 0 %classargs = (from => $1, to => $2);
78 }
79 # Date value
80 elsif( lc($value) eq 'date' ){
81 0 $class = $pkg->get_factory_class('date')
82 }
83 # Day of week
84 elsif( lc($value) eq 'day of week' ){
85 0 $class = $pkg->get_factory_class('list');
86 0 %classargs = (
87 list => [
88 'monday', 'mon',
89 'tuesday', 'tue',
90 'wednesday', 'wed',
91 'thursday', 'thu',
92 'friday', 'fri',
93 'saturday', 'sat',
94 'sunday', 'sun'
95 ]);
96 }
97 # Time value
98 elsif( lc($value) eq 'time' ){
99 0 $class = $pkg->get_factory_class('time');
100 }
101 # Speed
102 elsif( lc($value) eq 'speed' ){
103 0 $class = $pkg->get_factory_class('numwithunit');
104 0 %classargs = (
105 units => [
106 'kph', 'km/h',
107 'mph', 'knots'
108 ]
109 );
110 }
111 # Lengths
112 ▶ elsif( lc($value) eq 'length' || lc($value) eq 'height' || lc($value) eq 'width' ){
Condition0%0/6
lc $value eq "length" or lc $value eq "height" or lc $value eq "width"
l!l&&r!l&&!r
000
lc $value eq "length" or lc $value eq "height"
l!l&&r!l&&!r
000
MC/DC0%0/3
lc $value eq "length" or lc $value eq "height" or lc $value eq "width"
lc $value eq "length" lc $value eq "height" lc $value eq "width"
Truth table0%0/4
A or B or C
A= lc $value eq "length"B= lc $value eq "height"C= lc $value eq "width"
ABCresult
1XX1
01X1
0011
0000
113 0 $class = $pkg->get_factory_class('numwithunit');
114 0 %classargs = (
115 units => [
116 'mm', 'cm', 'dm', 'm', 'km',
117 'mil', # Scandinavian mil (10km)
118 'inch', 'foot', 'yard', 'mile',
119 'nm', # Nautical mile
120 'furlong'
121 ]
122 );
123 }
124  
125 0 my $self = bless( {value => $value}, $class);
126  
127 0 return $self->init($value, \%classargs, @_);
128 }
129  
130 # Inheriting classes need to override this method if they get arguments
131 0 ▶sub init {
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
132 0 my $self = shift;
133  
134 confess "BUG: Subclass with arguments haven't overriden init. classargs=$_[1]"
135 0 ▶ if %{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
if %{$_[1];} 0 0 0
136  
137 0 return $self;
138 }
139  
140 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod undocumented
141 0 my $self = shift;
142  
143 0 return $self->value();
144 }
145  
146 # Comparison operator
147 0 ▶sub compare {
Subroutine compare: not called CC=2 SCAR=17.9
Pod undocumented
148 0 my ($s1, $s2, $inverted) = @_;
149 0 ▶ return $inverted ? "$s2" cmp "$s1" : "$s1" cmp "$s2";
Branch: 1 branch
BranchTrueFalseTotal
$inverted ? : 0 0 0
150 }
151  
152 =head1 AUTHOR
153  
154 Knut Arne Bjørndal, C<< <bob at cakebox.net> >>
155  
156 =head1 BUGS
157  
158 Please report any bugs or feature requests to C<bug-geo-osm-mapfeatures-feature-value at rt.cpan.org>, or through
159 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Geo-OSM-MapFeatures>. I will be notified, and then you'll
160 automatically be notified of progress on your bug as I make changes.
161  
162  
163  
164  
165 =head1 SUPPORT
166  
167 You can find documentation for this module with the perldoc command.
168  
169 perldoc Geo::OSM::MapFeatures
170  
171  
172 You can also look for information at:
173  
174 =over 4
175  
176 =item * RT: CPAN's request tracker
177  
178 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Geo-OSM-MapFeatures>
179  
180 =item * AnnoCPAN: Annotated CPAN documentation
181  
182 L<http://annocpan.org/dist/Geo-OSM-MapFeatures>
183  
184 =item * CPAN Ratings
185  
186 L<http://cpanratings.perl.org/d/Geo-OSM-MapFeatures>
187  
188 =item * Search CPAN
189  
190 L<http://search.cpan.org/dist/Geo-OSM-MapFeatures>
191  
192 =back
193  
194  
195 =head1 ACKNOWLEDGEMENTS
196  
197  
198 =head1 COPYRIGHT & LICENSE
199  
200 Copyright 2008-2009 Knut Arne Bjørndal, all rights reserved.
201  
202 This program is free software; you can redistribute it and/or modify it
203 under the same terms as Perl itself.
204  
205  
206 =cut
207  
208 2 1; # End of Geo::OSM::MapFeatures::Feature::Value
↑ Summary MapFeatures/Feature.pm »