Created
November 25, 2010 11:39
-
-
Save wchristian/715252 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
package TFX::Flight; | |
use Moose; | |
use MooseX::HasDefaults::RO; | |
use Class::Load 'load_class'; | |
use lib '..'; | |
use TFX::Sealtix; | |
has table_name => ( isa => 'Str', lazy_build => 1 ); | |
sub _build_table_name { "OWF" } | |
sub build { | |
my ( $class, %args ) = @_; | |
my $source = delete $args{source}; | |
my $engine = "$class\::$source"; | |
load_class( $engine ); | |
return $engine->new( $args{data} ); | |
} | |
sub as_hash { | |
my ( $self ) = @_; | |
my $half_return = $self->half_return; | |
my $air_rule_set = $half_return->{airRuleSet}; | |
my $price = $half_return->{farePassengerTypePriceList}[0]{purchasePrice}; # kann auch ticketingPrice sein | |
$self->{currency} = $price->{currencyIsoCode}; | |
$self->{price_one_way} = $price->{value}; | |
$self->{combination_id} = $air_rule_set->{openJawCombinationGroup}{name}; | |
$self->{season_surcharge} = $self->calculate_tax_addition( $half_return->{taxQuoteList} ); | |
$self->{duration_rules} = $self->generate_duration_rules( $air_rule_set ); | |
$self->{flight_class} = $self->convert_flight_class( $air_rule_set->{cabinClass}{id} ); | |
my $segments = $self->itinerary->{segmentList}; | |
$self->extract_generic_flight_data_from_seg( $segments->[0] ); | |
$self->process_multi_legs( @{ $segments } ); | |
$self->add_default_fields; | |
return $self->make_hash; | |
} | |
sub make_hash { | |
my ( $self ) = @_; | |
my @fields = TFX::Sealtix->get_fields; | |
my %hash = map $self->_get_field_value($_), @fields; | |
return \%hash; | |
} | |
sub _get_field_value { | |
my ( $self, $field ) = @_; | |
my $sub = $self->can( $field ); | |
return ( $field => $sub->() ) if $sub and defined $sub->(); | |
warn "$field undefined"; | |
return ( $field => $self->{$field} ) if defined $self->{$field}; | |
return; | |
} | |
1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Can't call method "can" on unblessed reference at accessor table_name defined at lib/TFX/Flight.pm line 16 | |
TFX::Flight::table_name('HASH(0x4775d0c)') called at lib/TFX/Flight.pm line 64 | |
TFX::Flight::_get_field_value('TFX::Flight::Conex=HASH(0x4a7fc2c)', 'table_name') called at lib/TFX/Flight.pm line 55 | |
TFX::Flight::make_hash('TFX::Flight::Conex=HASH(0x4a7fc2c)') called at lib/TFX/Flight.pm line 47 | |
TFX::Flight::as_hash('TFX::Flight::Conex=HASH(0x4a7fc2c)') called at D:\traffics\conex_converter\t\flight_list_generation.t line 40 | |
flight_list_generation::run() called at D:\traffics\conex_converter\t\flight_list_generation.t line 24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment