| 1 | package WWW::EFA::LocationFactory; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use WWW::EFA::Location; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use WWW::EFA::Coordinates; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use WWW::EFA::CoordinatesFactory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | WWW::EFA::LocationFactory - A Factory for creating L<WWW::EFA::Location> objects. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Version 0.01 | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | my $factory = WWW::EFA::LocationFactory->new(); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | TODO: RCL 2012-01-22 Documentation | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | has 'coord_factory' => ( is => 'ro', isa => 'WWW::EFA::CoordinatesFactory', lazy => 1, | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | default => sub{ WWW::EFA::CoordinatesFactory->new() }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 2 | ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head2 location_from_odvNameElem | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Returns a L<WWW::EFA::Location> object | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | my $location = $factory->location_from_odvNameElem( $itd_odv->findnodes( 'odvNameElem' ) ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Expects an XML::LibXML::Element of XML like this: | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | <odvNameElem x="11534639.00000" y="48142484.00000" | ||||||||||||||||||||||||||||
| 47 | mapName="WGS84" stopID="8" value="8:1" isTransferStop="0" | ||||||||||||||||||||||||||||
| 48 | matchQuality="100000">Donnersbergerbrücke</odvNameElem> | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub location_from_odvNameElem { | ||||||||||||||||||||||||||
|
Subroutine
location_from_odvNameElem: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | 0 | my $elem = shift; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | #TODO: RCL 2011-09-15 There must be a better way to do this... | ||||||||||||||||||||||||||||
| 56 | 0 | my @mapping_as_array = ( | |||||||||||||||||||||||||||
| 57 | anyType => 'type', | ||||||||||||||||||||||||||||
| 58 | id => 'id', | ||||||||||||||||||||||||||||
| 59 | locality => 'locality', | ||||||||||||||||||||||||||||
| 60 | mapName => 'map_name', | ||||||||||||||||||||||||||||
| 61 | matchQuality => 'match_quality', | ||||||||||||||||||||||||||||
| 62 | objectName => 'name', | ||||||||||||||||||||||||||||
| 63 | poiID => 'poi_id', | ||||||||||||||||||||||||||||
| 64 | streetID => 'street_id', | ||||||||||||||||||||||||||||
| 65 | isTransferStop => 'is_transfer_stop', | ||||||||||||||||||||||||||||
| 66 | value => 'value', | ||||||||||||||||||||||||||||
| 67 | stopID => 'id', | ||||||||||||||||||||||||||||
| 68 | place => 'name', | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my @mapping_keys; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | foreach( my $idx = 0; $idx < scalar( @mapping_as_array ); $idx += 2 ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | unshift( @mapping_keys, $mapping_as_array[$idx] ); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 0 | my %mapping = @mapping_as_array; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Transform the location data to the format understood by WWW::EFA::Location | ||||||||||||||||||||||||||||
| 78 | my %loc_data = | ||||||||||||||||||||||||||||
| 79 | 0 | map { $mapping{ $_ } => $elem->getAttribute( $_ ) } # Create the new hash | |||||||||||||||||||||||||||
| 80 | 0 | grep{ $elem->hasAttribute( $_ ) } # Only those which were defined in the data | |||||||||||||||||||||||||||
| 81 | 0 | grep{ $mapping{ $_ } } # Remove any whose mapping is undefined | |||||||||||||||||||||||||||
| 82 | @mapping_keys; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $loc_data{name} ||= $elem->textContent(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$loc_data{"name"} ||= $elem->textContent
MC/DC0%0/2
$loc_data{"name"} ||= $elem->textContent
$loc_data{"name"}
$elem->textContent
Truth table0%0/3
A ||= B
A= $loc_data{"name"}B= $elem->textContent
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # Clean up the encoding on the text strings | ||||||||||||||||||||||||||||
| 87 | %loc_data = | ||||||||||||||||||||||||||||
| 88 | 0 | map { $_ => $loc_data{$_} } | |||||||||||||||||||||||||||
| 89 | keys %loc_data; | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $coordinates = $self->coord_factory->coordinates_from_XY( $elem ); | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | $loc_data{ coordinates } = $coordinates if( $coordinates ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | my $loc = WWW::EFA::Location->new( %loc_data ); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | return $loc; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head2 location_from_itdOdvAssignedStop | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Same as location_from_odvNameElem because these are basically the same XML, but | ||||||||||||||||||||||||||||
| 102 | different element name. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub location_from_itdOdvAssignedStop { | ||||||||||||||||||||||||||
|
Subroutine
location_from_itdOdvAssignedStop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 107 | 0 | return $self->location_from_odvNameElem( @_ ); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head2 location_from_coordInfoItem | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | Returns a L<WWW::EFA::Location> object | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | my $location = $factory->location_from_coordInfoItem( $itd_odv->findnodes( 'coordInfoItem' ) ); | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | Expects an XML::LibXML::Element of XML like this: | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | <coordInfoItem type="STOP" id="64" name="Barthstraße" addName="" omc="9162000" | ||||||||||||||||||||||||||||
| 121 | placeID="1" locality="München" gisLayer="SYS-STOP" gisID="64" | ||||||||||||||||||||||||||||
| 122 | distance="190" stateless="64"> | ||||||||||||||||||||||||||||
| 123 | <itdPathCoordinates> | ||||||||||||||||||||||||||||
| 124 | <coordEllipsoid>WGS84</coordEllipsoid> | ||||||||||||||||||||||||||||
| 125 | <coordType>GEO_DECIMAL</coordType> | ||||||||||||||||||||||||||||
| 126 | <itdCoordinateString decimal="." cs="," ts=" ">11529230.00000,48140331.00000</itdCoordinateString> | ||||||||||||||||||||||||||||
| 127 | </itdPathCoordinates> | ||||||||||||||||||||||||||||
| 128 | <genAttrList> | ||||||||||||||||||||||||||||
| 129 | <genAttrElem> | ||||||||||||||||||||||||||||
| 130 | <name>STOP_NAME_WITH_PLACE </name> | ||||||||||||||||||||||||||||
| 131 | <value>Barthstraße</value> | ||||||||||||||||||||||||||||
| 132 | </genAttrElem> | ||||||||||||||||||||||||||||
| 133 | <genAttrElem> | ||||||||||||||||||||||||||||
| 134 | <name>STOP_MAJOR_MEANS</name> | ||||||||||||||||||||||||||||
| 135 | <value>4</value> | ||||||||||||||||||||||||||||
| 136 | </genAttrElem> | ||||||||||||||||||||||||||||
| 137 | </genAttrList> | ||||||||||||||||||||||||||||
| 138 | </coordInfoItem> | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub location_from_coordInfoItem { | ||||||||||||||||||||||||||
|
Subroutine
location_from_coordInfoItem: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 143 | 0 | my $elem = shift; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if( not $elem->hasAttribute( 'type' ) or $elem->getAttribute( 'type' ) ne 'STOP' ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $elem->hasAttribute("type") or $elem->getAttribute("type") ne "STOP"
MC/DC0%0/2
not $elem->hasAttribute("type") or $elem->getAttribute("type") ne "STOP"
not $elem->hasAttribute("type")
$elem->getAttribute("type") ne "STOP"
Truth table0%0/3
not(A) or B
A= not $elem->hasAttribute("type")B= $elem->getAttribute("type") ne "STOP"
| |||||||||||||||||||||||||||||
| 146 | 0 | croak( sprintf "Unknown location type found: %s", $elem->getAttribute( 'type' ) ); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | my( $coord_elem ) = $elem->findnodes( 'itdPathCoordinates' ); | |||||||||||||||||||||||||||
| 150 | 0 | ▶ | if( not $coord_elem ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | croak( "Could not find itdPathCoordinates\n" . $elem->toString( 2 ) ); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | my $coordinates = $self->coord_factory->coordinates_from_itdPathCoordinates( $coord_elem ); | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if( not $coordinates or 0 ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
not $coordinates or 0
MC/DC0%0/1
not $coordinates or 0
not $coordinates
Truth table0%0/2
not(A)
A= not $coordinates
| |||||||||||||||||||||||||||||
| 157 | 0 | croak( "No coordinate found in coordInfoItem\n" . $coord_elem->toString ); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | my %loc_params = | ||||||||||||||||||||||||||||
| 161 | 0 | map { $_ => $elem->getAttribute( $_ ) } | |||||||||||||||||||||||||||
| 162 | 0 | grep { $elem->hasAttribute( $_ ) } | |||||||||||||||||||||||||||
| 163 | qw/name locality distance id/; | ||||||||||||||||||||||||||||
| 164 | 0 | $loc_params{coordinates} = $coordinates; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | my $loc = WWW::EFA::Location->new( %loc_params ); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | return $loc; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =head2 location_from_itdPoint | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | Returns a L<WWW::EFA::Location> object | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | my $location = $factory->location_from_itdPoint( $doc->findnodes( 'itdPoint' ) ); | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | Expects an XML::LibXML::Element of XML like this: | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | <itdPoint stopID="64" area="20" platform="18H19" name="Barthstraße" | ||||||||||||||||||||||||||||
| 182 | nameWO="Barthstraße" platformName="" usage="departure" | ||||||||||||||||||||||||||||
| 183 | x="11529096.00000" y="48140348.00000" mapName="WGS84" | ||||||||||||||||||||||||||||
| 184 | omc="9162000" placeID="1" locality="München"> | ||||||||||||||||||||||||||||
| 185 | </itdPoint> | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =cut | ||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub location_from_itdPoint { | ||||||||||||||||||||||||||
|
Subroutine
location_from_itdPoint: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 189 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 190 | 0 | my $elem = shift; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | my %mapping = ( | |||||||||||||||||||||||||||
| 194 | stopID => 'id', | ||||||||||||||||||||||||||||
| 195 | platform => 'platform', | ||||||||||||||||||||||||||||
| 196 | name => 'name', | ||||||||||||||||||||||||||||
| 197 | usage => 'usage', | ||||||||||||||||||||||||||||
| 198 | mapName => 'mapName', | ||||||||||||||||||||||||||||
| 199 | ); | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | my %loc_params = | ||||||||||||||||||||||||||||
| 202 | 0 | map { $mapping{ $_ } => $elem->getAttribute( $_ ) } | |||||||||||||||||||||||||||
| 203 | 0 | grep { $elem->hasAttribute( $_ ) } | |||||||||||||||||||||||||||
| 204 | keys( %mapping ); | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | my $coordinates = $self->coord_factory->coordinates_from_XY( $elem ); | |||||||||||||||||||||||||||
| 207 | 0 | ▶ | $loc_params{coordinates} = $coordinates if( $coordinates ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | my $location = WWW::EFA::Location->new( %loc_params ); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | return $location; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 2 | 1; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | Copyright 2011, Robin Clarke, Munich, Germany | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | Robin Clarke <perl@robinclarke.net> | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||