| 1 | package WWW::EFA::RouteFactory; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use WWW::EFA::Route; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use WWW::EFA::PartialRoute; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use WWW::EFA::DateFactory; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use WWW::EFA::Stop; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | WWW::EFA::RouteFactory - A factory for creating L<WWW::EFA::Route> objects. | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | Version 0.02 | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | my $factory = WWW::EFA::RouteFactory->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | TODO: RCL 2012-01-22 Documentation | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | has 'location_factory' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | isa => 'WWW::EFA::LocationFactory', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | default => sub{ WWW::EFA::LocationFactory->new() }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | has 'date_factory' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | isa => 'WWW::EFA::DateFactory', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | default => sub{ WWW::EFA::DateFactory->new() }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | =head2 route_from_itdRoute | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | Returns a L<WWW::EFA::Route> object | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | my $route = $factory->route_from_itdRoute( $element ); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | Expects an L<XML::LibXML::Element> of XML with this kind of XML: | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | TODO: RCL 2012-01-22 Example XML | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub route_from_itdRoute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
route_from_itdRoute: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $elem = shift; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $route = WWW::EFA::Route->new( | |||||||||||||||||||||||||||||||||||||||||
| 66 | changes => $elem->getAttribute( 'changes' ), | ||||||||||||||||||||||||||||||||||||||||||
| 67 | vehicle_time => $elem->getAttribute( 'vehicleTime' ), | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # TODO: RCL 2011-11-11 Implement handling for itdFare for #fares | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # my @fares = $elem->findnodes( 'itdfare' ); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my @partials; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | foreach my $part_elem ( $elem->findnodes( 'itdPartialRouteList/itdPartialRoute' ) ){ | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $partial = $self->partial_from_itdPartialRoute( $part_elem ); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | push( @partials, $partial ); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | # TODO: RCL 2011-11-11 Sort @partial | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # Get earliest depart and latest arrive from @partial | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my %times; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | foreach my $partial( @partials ){ | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if( not $times{departure} or $partial->departure_time < $times{departure} ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $times{"departure"} or $partial->departure_time < $times{"departure"}
MC/DC0%0/2
not $times{"departure"} or $partial->departure_time < $times{"departure"}
not $times{"departure"}
$partial->departure_time < $times{"departure"}
Truth table0%0/3
not(A) or B
A= not $times{"departure"}B= $partial->departure_time < $times{"departure"}
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $times{departure} = $partial->departure_time; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if( not $times{arrival} or $partial->arrival_time > $times{arrival} ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $times{"arrival"} or $partial->arrival_time > $times{"arrival"}
MC/DC0%0/2
not $times{"arrival"} or $partial->arrival_time > $times{"arrival"}
not $times{"arrival"}
$partial->arrival_time > $times{"arrival"}
Truth table0%0/3
not(A) or B
A= not $times{"arrival"}B= $partial->arrival_time > $times{"arrival"}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $times{arrival} = $partial->arrival_time; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $route->arrival_time( $times{arrival} ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $route->departure_time( $times{departure} ); | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $route->partial_routes( \@partials ); | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return $route; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head2 partial_from_itdPartialRoute | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | Returns a L<WWW::EFA::PartialRoute> object | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | my $route = $factory->partial_from_itdPartialRoute( $part_element ); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | Expects an L<XML::LibXML::Element> of XML with this kind of XML: | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | TODO: RCL 2012-01-22 Example XML | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub partial_from_itdPartialRoute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
partial_from_itdPartialRoute: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $elem = shift; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # TODO: RCL 2011-11-11 There's so much more stuff in here which we could use... | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # itdStopSeq - the sequence of stops for each partial | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my %part_route_params; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | foreach my $point_elem ( $elem->findnodes( 'itdPoint' ) ){ | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $location = $self->location_factory->location_from_itdPoint( $point_elem ); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if( $location and $location->usage and $location->usage =~ m/^(departure|arrival)$/ ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$location and $location->usage and $location->usage =~ /^(departure|arrival)$/
$location and $location->usage
MC/DC0%0/3
$location and $location->usage and $location->usage =~ /^(departure|arrival)$/
$location
$location->usage
$location->usage =~ /^(departure|arrival)$/
Truth table0%0/4
A and B and C
A= $locationB= $location->usageC= $location->usage =~ /^(departure|arrival)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $part_route_params{$location->usage . '_location'} = $location; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my( $date_elem ) = $point_elem->findnodes( 'itdDateTime' ); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if( $date_elem ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $time = $self->date_factory->date_from_itdDateTime( $date_elem ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $part_route_params{$location->usage . '_time'} = $time; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my @stops; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | foreach my $stop_elem ( $elem->findnodes( 'itdStopSeq/itdPoint' ) ){ | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $location = $self->location_factory->location_from_itdPoint( $stop_elem ); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my %stop_params = ( location => $location ); | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my @times; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | foreach my $time_elem ( $stop_elem->findnodes( 'itdDateTime' ) ){ | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $time = $self->date_factory->date_from_itdDateTime( $time_elem ); | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | push( @times, $time ) if $time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | @times = sort{ $a <=> $b } @times; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if( scalar( @times ) > 0 ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $stop_params{departure_time} = $times[0]; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $stop_params{arrival_time} = $times[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $stop = WWW::EFA::Stop->new( %stop_params ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | push( @stops, $stop ); | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $part_route_params{stops} = \@stops; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $partial = WWW::EFA::PartialRoute->new( %part_route_params ); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return $partial; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | Copyright 2011, Robin Clarke, Munich, Germany | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | Robin Clarke <perl@robinclarke.net> | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||