| 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; | ||||||||||||||||||||||||||||
| 6 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | $Data::Conveyor::Service::Result::Tabular::VERSION = '1.103130'; | |||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Stage-based conveyor-belt-like ticket handling system | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Text::Table; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Data::Miscellany 'trim'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use parent 'Data::Conveyor::Service::Result'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | __PACKAGE__->mk_array_accessors(qw(headers rows)); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub result_as_string { | ||||||||||||||||||||||||||
|
Subroutine
result_as_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 18 | 0 | ▶ | unless ($self->rows_count) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | return "No results\n"; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 0 | my @fields = $self->headers; | |||||||||||||||||||||||||||
| 22 | 0 | my $table = Text::Table->new(@fields); | |||||||||||||||||||||||||||
| 23 | 0 | $table->load($self->rows); | |||||||||||||||||||||||||||
| 24 | 0 | $table; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Given a LoH (list of hashes, a typical DBI result set), it populates the | ||||||||||||||||||||||||||||
| 28 | # result object with those rows. It can also be a list of objects if those | ||||||||||||||||||||||||||||
| 29 | # objects have methods that correspond to the headers. | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub set_from_rows { | ||||||||||||||||||||||||||
|
Subroutine
set_from_rows: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 32 | 0 | my ($did_set_headers, $count); | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $limit = $args{limit} if defined $args{limit}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my @fields = @{ $args{fields} } if defined $args{fields}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | for my $row (@{ $args{rows} }) { | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | last if defined($limit) && ++$count > $limit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $limit and ++$count > $limit
MC/DC0%0/2
defined $limit and ++$count > $limit
defined $limit
++$count > $limit
Truth table0%0/3
A and B
A= defined $limitB= ++$count > $limit
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | unless ($did_set_headers) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | scalar @fields or @fields = sort keys %$row; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | $self->headers(@fields); | |||||||||||||||||||||||||||
| 40 | 0 | $did_set_headers++; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 0 | my @values; | |||||||||||||||||||||||||||
| 43 | 0 | for (@fields) { | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (ref $row eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 45 | 0 | push @values => $row->{$_}; | |||||||||||||||||||||||||||
| 46 | } elsif (UNIVERSAL::can($row, $_)) { | ||||||||||||||||||||||||||||
| 47 | 0 | push @values => $row->$_; | |||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||
| 49 | 0 | throw Error::Hierarchy::Internal::CustomMessage( | |||||||||||||||||||||||||||
| 50 | custom_message => "can't set field [$_] from row [$row]"); | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $self->rows_push([ map { defined($_) ? $_ : '' } @values ]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | $self; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub result { $_[0]->rows } | ||||||||||||||||||||||||||
|
Subroutine
result: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub result_as_list_of_hashes { | ||||||||||||||||||||||||||
|
Subroutine
result_as_list_of_hashes: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 0 | my @result; | |||||||||||||||||||||||||||
| 62 | 0 | my @headers = $self->headers; # don't call this accessor for every row | |||||||||||||||||||||||||||
| 63 | 0 | for my $row_ref ($self->rows) { | |||||||||||||||||||||||||||
| 64 | 0 | my $index = 0; | |||||||||||||||||||||||||||
| 65 | 0 | my %row_hash; | |||||||||||||||||||||||||||
| 66 | 0 | for my $header (@headers) { | |||||||||||||||||||||||||||
| 67 | 0 | $row_hash{$header} = $row_ref->[ $index++ ]; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | push @result => \%row_hash; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | wantarray ? @result : \@result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 1 | 1; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||