| 1 | 1 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | package Data::Conveyor::Service::Result::Tabular_TEST; | ||
| 6 | 1 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | $Data::Conveyor::Service::Result::Tabular_TEST::VERSION = '1.103130'; | |
| 8 | } | ||
| 9 | # ABSTRACT: Stage-based conveyor-belt-like ticket handling system | ||
| 10 | |||
| 11 | 1 | ▶ | use Error::Hierarchy::Test 'throws2_ok'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 1 | ▶ | use Test::More; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 1 | ▶ | use parent 'Data::Conveyor::Test'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | use constant PLAN => 5; | ||
| 15 | |||
| 16 | sub run { | ||
| 17 | my $self = shift; | ||
| 18 | $self->SUPER::run(@_); | ||
| 19 | $self->test_list_of_hashes_input; | ||
| 20 | $self->test_list_of_objects_input_ok; | ||
| 21 | $self->test_list_of_objects_input_no_baz; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub test_list_of_hashes_input { | ||
| 25 | my $self = shift; | ||
| 26 | my $o = $self->make_real_object; | ||
| 27 | my $rows = [ | ||
| 28 | { foo => 'row0foo', bar => 'row0bar', baz => 'row0baz' }, | ||
| 29 | { foo => 'row1foo', bar => 'row1bar', baz => 'row1baz' }, | ||
| 30 | { foo => 'row2foo', bar => 'row2bar', baz => 'row2baz' }, | ||
| 31 | ]; | ||
| 32 | $o->set_from_rows( | ||
| 33 | fields => [qw/foo bar baz/], | ||
| 34 | rows => $rows, | ||
| 35 | ); | ||
| 36 | is_deeply( | ||
| 37 | scalar $o->rows, | ||
| 38 | [ [qw/row0foo row0bar row0baz/], [qw/row1foo row1bar row1baz/], | ||
| 39 | [qw/row2foo row2bar row2baz/], | ||
| 40 | ], | ||
| 41 | 'list of hashes input: rows()' | ||
| 42 | ); | ||
| 43 | is_deeply(scalar $o->result_as_list_of_hashes, | ||
| 44 | $rows, 'list of hashes input: result_as_list_of_hashes()'); | ||
| 45 | } | ||
| 46 | |||
| 47 | sub test_list_of_objects_input_ok { | ||
| 48 | my $self = shift; | ||
| 49 | my $o = $self->make_real_object; | ||
| 50 | my $rows = [ | ||
| 51 | Data::Conveyor::Temp001->new(row => 0), | ||
| 52 | Data::Conveyor::Temp001->new(row => 1), | ||
| 53 | Data::Conveyor::Temp001->new(row => 2), | ||
| 54 | ]; | ||
| 55 | $o->set_from_rows( | ||
| 56 | fields => [qw/foo bar baz/], | ||
| 57 | rows => $rows, | ||
| 58 | ); | ||
| 59 | is_deeply( | ||
| 60 | scalar $o->rows, | ||
| 61 | [ [qw/row0foo row0bar row0baz/], [qw/row1foo row1bar row1baz/], | ||
| 62 | [qw/row2foo row2bar row2baz/], | ||
| 63 | ], | ||
| 64 | 'list of objects input (ok): rows()' | ||
| 65 | ); | ||
| 66 | is_deeply( | ||
| 67 | scalar $o->result_as_list_of_hashes, | ||
| 68 | [ { foo => 'row0foo', bar => 'row0bar', baz => 'row0baz' }, | ||
| 69 | { foo => 'row1foo', bar => 'row1bar', baz => 'row1baz' }, | ||
| 70 | { foo => 'row2foo', bar => 'row2bar', baz => 'row2baz' }, | ||
| 71 | ], | ||
| 72 | 'list of objects input (ok): result_as_list_of_hashes()' | ||
| 73 | ); | ||
| 74 | } | ||
| 75 | |||
| 76 | sub test_list_of_objects_input_no_baz { | ||
| 77 | my $self = shift; | ||
| 78 | my $o = $self->make_real_object; | ||
| 79 | my $rows = [ | ||
| 80 | Data::Conveyor::Temp002->new(row => 0), | ||
| 81 | Data::Conveyor::Temp002->new(row => 1), | ||
| 82 | Data::Conveyor::Temp002->new(row => 2), | ||
| 83 | ]; | ||
| 84 | throws2_ok { | ||
| 85 | $o->set_from_rows( | ||
| 86 | fields => [qw/foo bar baz/], | ||
| 87 | rows => $rows, | ||
| 88 | ); | ||
| 89 | } | ||
| 90 | 'Error::Hierarchy::Internal::CustomMessage', | ||
| 91 | qr/can't set field \[baz\] from row \[Data::Conveyor::Temp002=HASH\(/, | ||
| 92 | "set_from_rows() using objects that can't baz()"; | ||
| 93 | } | ||
| 94 | |||
| 95 | package Data::Conveyor::Temp001; | ||
| 96 | BEGIN { | ||
| 97 | $Data::Conveyor::Temp001::VERSION = '1.103130'; | ||
| 98 | } | ||
| 99 | use parent 'Class::Accessor::Complex'; | ||
| 100 | __PACKAGE__->mk_new->mk_scalar_accessors(qw(row)); | ||
| 101 | sub foo { sprintf 'row%dfoo', $_[0]->row } | ||
| 102 | sub bar { sprintf 'row%dbar', $_[0]->row } | ||
| 103 | sub baz { sprintf 'row%dbaz', $_[0]->row } | ||
| 104 | |||
| 105 | package Data::Conveyor::Temp002; | ||
| 106 | BEGIN { | ||
| 107 | $Data::Conveyor::Temp002::VERSION = '1.103130'; | ||
| 108 | } | ||
| 109 | use parent 'Class::Accessor::Complex'; | ||
| 110 | __PACKAGE__->mk_new->mk_scalar_accessors(qw(row)); | ||
| 111 | sub foo { sprintf 'row%dfoo', $_[0]->row } | ||
| 112 | sub bar { sprintf 'row%dbar', $_[0]->row } | ||
| 113 | |||
| 114 | # this class can't baz() | ||
| 115 | 1; | ||
| 116 | |||
| 117 | |||
| 118 | __END__ | ||