| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Amazon::MechanicalTurk::RowData::ArrayHashRowData; | 
| 2 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 49 |  | 
| 3 | 1 |  |  | 1 |  | 7 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 4 | 1 |  |  | 1 |  | 5 | use Carp; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 123 |  | 
| 5 | 1 |  |  | 1 |  | 6 | use Net::Amazon::MechanicalTurk::RowData; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 336 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '1.00'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our @ISA = qw{ Net::Amazon::MechanicalTurk::RowData }; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | Net::Amazon::MechanicalTurk::RowData::ArrayHashRowData->attributes(qw{ | 
| 12 |  |  |  |  |  |  | array | 
| 13 |  |  |  |  |  |  | }); | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | # | 
| 16 |  |  |  |  |  |  | # Creates a RowData from an array of hashes. | 
| 17 |  |  |  |  |  |  | # If fieldNames are not given the sorted keys of the first | 
| 18 |  |  |  |  |  |  | # hash become the fieldNames. | 
| 19 |  |  |  |  |  |  | # | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub init { | 
| 22 | 1 |  |  | 1 | 0 | 2 | my $self = shift; | 
| 23 | 1 |  |  |  |  | 10 | $self->setAttributes(@_); | 
| 24 | 1 |  |  |  |  | 10 | $self->assertRequiredAttributes(qw{ array }); | 
| 25 | 1 | 50 | 33 |  |  | 8 | if (!$self->fieldNames and $#{$self->array} >= 0) { | 
|  | 1 |  |  |  |  | 4 |  | 
| 26 | 1 |  |  |  |  | 3 | my $firstHash = $self->array->[0]; | 
| 27 | 1 | 50 |  |  |  | 5 | if (!UNIVERSAL::isa($firstHash, "HASH")) { | 
| 28 | 0 |  |  |  |  | 0 | Carp::croak("Non hash found in first element of array."); | 
| 29 |  |  |  |  |  |  | } | 
| 30 | 1 |  |  |  |  | 9 | $self->fieldNames([sort keys(%$firstHash)]); | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  | else { | 
| 33 | 0 |  |  |  |  | 0 | $self->fieldNames([]); | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub each { | 
| 38 | 1 |  |  | 1 | 0 | 22 | my ($self, $block, @blockXArgs) = @_; | 
| 39 | 1 |  |  |  |  | 4 | my $array = $self->array; | 
| 40 | 1 |  |  |  |  | 2 | foreach my $element (@$array) { | 
| 41 | 20 |  |  |  |  | 80 | $block->($self, $element, @blockXArgs); | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | return 1; |