| 1 | package WWW::AzimuthAero::Flight; | ||||||||||||||||||||||||||||
| 2 | 1 | $WWW::AzimuthAero::Flight::VERSION = '0.3'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Flight representation | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | use Class::Tiny qw( | |||||||||||||||||||||||||||
| 11 | from_city | ||||||||||||||||||||||||||||
| 12 | to_city | ||||||||||||||||||||||||||||
| 13 | flight_num | ||||||||||||||||||||||||||||
| 14 | flight_date | ||||||||||||||||||||||||||||
| 15 | departure_time | ||||||||||||||||||||||||||||
| 16 | arrival_time | ||||||||||||||||||||||||||||
| 17 | trip_duration | ||||||||||||||||||||||||||||
| 18 | fares | ||||||||||||||||||||||||||||
| 19 | has_stops | ||||||||||||||||||||||||||||
| 20 | stop_at_city | ||||||||||||||||||||||||||||
| 21 | 1 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use List::Compare; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub as_hashref { | ||||||||||||||||||||||||||||
| 27 | 6 | ▶ | my ( $self, %params ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
as_hashref: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # if defined $params{skip_undef}; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | my @fields_to_return = | ||||||||||||||||||||||||||||
| 32 | ( defined $params{only} ) | ||||||||||||||||||||||||||||
| 33 | 6 | ▶ | ? ( @{ $params{only} } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | : ( Class::Tiny->get_all_attributes_for( ref($self) ) ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 6 | my $result = {}; | |||||||||||||||||||||||||||
| 37 | 6 | for my $x (@fields_to_return) { | |||||||||||||||||||||||||||
| 38 | 45 | ▶ | if ( $self->can($x) && not _in_array( $params{skip}, $x ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->can($x) and not _in_array($params{"skip"}, $x)
MC/DC50%1/2
$self->can($x) and not _in_array($params{"skip"}, $x)
$self->can($x)
not _in_array($params{"skip"}, $x)
Truth table66%2/3
A and not(B)
A= $self->can($x)B= not _in_array($params{"skip"}, $x)
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | #$result->{$x} = $self->$x; | ||||||||||||||||||||||||||||
| 41 | 42 | ▶ | if ( $params{skip_undef} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 20 | ▶ | $result->{$x} = $self->$x if defined $self->$x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||
| 45 | 22 | $result->{$x} = $self->$x; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 6 | return $result; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub as_string { | ||||||||||||||||||||||||||||
| 54 | 2 | ▶ | my ( $self, %params ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | my $hash = $self->as_hashref( skip_undef => 1 ); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # ref($hash->{$k}) eq '' for skipping fares | ||||||||||||||||||||||||||||
| 59 | 2 | my @str = (); | |||||||||||||||||||||||||||
| 60 | 2 | ▶ | if ( $params{order} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 1 | for my $k ( @{ $params{order} } ) { | |||||||||||||||||||||||||||
| 62 | 2 | ▶ | push @str, $hash->{$k} if ( ref( $hash->{$k} ) eq '' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 2 | ▶ | push @str, $hash->{fares}{lowest} if ( $k eq 'fares' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | my $lc = List::Compare->new( $params{order}, [ keys %$hash ] ); | |||||||||||||||||||||||||||
| 67 | 1 | my @Ronly = $lc->get_Ronly; | |||||||||||||||||||||||||||
| 68 | 1 | for my $k (@Ronly) { | |||||||||||||||||||||||||||
| 69 | 5 | ▶ | push @str, $hash->{$k} if ( ref( $hash->{$k} ) eq '' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 5 | ▶ | push @str, $hash->{fares}{lowest} if ( $k eq 'fares' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # compare diff and push others | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||||||||
| 76 | 1 | for my $k ( sort keys %$hash ) { | |||||||||||||||||||||||||||
| 77 | 7 | ▶ | push @str, $hash->{$k} if ( ref( $hash->{$k} ) eq '' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 7 | ▶ | push @str, $hash->{fares}{lowest} if ( $k eq 'fares' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | ▶ | my $sep = ( defined $params{separator} ) ? $params{separator} : ' '; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | return join( $sep, @str ); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | sub _in_array { | ||||||||||||||||||||||||||||
| 88 | 45 | ▶ | my ( $array_ref, $pattern ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_in_array: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | no if ( $] >= 5.018 ), warnings => 'experimental'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 45 | ▶ | $array_ref //= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$array_ref //= []
MC/DC100%1/1
$array_ref //= []
$array_ref
Truth table100%2/2
A
A= $array_ref
| |||||||||||||||||||||||||||||
| 91 | 45 | return $pattern ~~ @{$array_ref}; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 1 | 1; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =pod | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 NAME | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | WWW::AzimuthAero::Flight - Flight representation | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 VERSION | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | version 0.3 | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | my $flight = WWW::AzimuthAero::Flight->new( | ||||||||||||||||||||||||||||
| 113 | from_city => 'ROV', | ||||||||||||||||||||||||||||
| 114 | to_city => 'KLF', | ||||||||||||||||||||||||||||
| 115 | flight_date => '16.06.2019' | ||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Object representation of data on pages like L<https://booking.azimuth.aero/!/ROV/LED/21.06.2019/1-0-0/> | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head1 METHODS | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head2 new | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | my $az = WWW::AzimuthAero::Flight->new(date => '16.06.2019', from => 'ROV', to => 'KLF'); | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 PROPERTIES | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head2 from_city | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | Departure city IATA code | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | Example: | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | LED | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head2 to_city | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Arrival city IATA code | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | Example: | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | ROV | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head2 flight_num | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Return string with flight number | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | Example: | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | A4 203 | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head2 flight_date | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | String in %d.%m.%Y format | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | Example: | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 24.06.2019 | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =head2 departure_time | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | Example: | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 07:20 | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head2 arrival_time | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | Example: | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 10:00 | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head2 trip_duration | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | Example: | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 5ч 35м | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =head2 fares | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | Contain hash with different tariffs | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||
| 185 | 'lowest' => '10680', | ||||||||||||||||||||||||||||
| 186 | 'optimalnyy' => '10680', | ||||||||||||||||||||||||||||
| 187 | 'svobodnyy' => '11980' | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | Possible keys are | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | qw/legkiy vygodnyy optimalnyy svobodnyy/ | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | lowest key always contains lowest price | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =head2 has_stops | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | Return true if flight consist of two flights | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | Like at L<https://booking.azimuth.aero/!/ROV/PKV/26.06.2019/1-0-0/> | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =head2 stop_at_city | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | Return IATA code of transit city | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head2 as_hashref | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Return particular properties as hash | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | $f->as_hash; | ||||||||||||||||||||||||||||
| 211 | $f->as_hash( skip => [ qw/fares/ ] ) | ||||||||||||||||||||||||||||
| 212 | $flight->as_hash( only => [ qw/from_city to_city flight_date/ ] ) | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | If class has such method but it's not set - will return undef in value | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | Convenient when inserting data to database, especially with L<DBIx::Class::ResultSet> | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | $schema->resultset('Flight')->create( $f->as_hash( skip => [ qw/fares/ ] ) ) | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | Params: | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | only - Which fields to return only | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | skip - Which fields skip from result = 'all except' | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | skip_undef - To skip or not undef values (useful to supress warning in concatenation) | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | =head2 as_string | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | Return flight info as string | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | Support same parameters as L<WWW::AzimuthAero::Flight> (in facts it's wrapper on it) | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | $f->as_string; | ||||||||||||||||||||||||||||
| 235 | $f->as_string( skip => [ qw/fares/ ] ) | ||||||||||||||||||||||||||||
| 236 | $flight->as_string( only => [ qw/from_city to_city flight_date/ ] ) | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | Additional parameters | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | order | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | $f->as_string( order => [ qw/price flight_date/ ] ) | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | By default (in order not specified) prints parameters in alphabetic order | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | Method could be useful for logging | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | separator | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | $f->as_string( separator => "\t" ) | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | Useful when you create a table | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | Pavel Serikov <pavelsr@cpan.org> | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | This software is copyright (c) 2019 by Pavel Serikov. | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 263 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =cut | ||||||||||||||||||||||||||||