| 1 | package Mojo::Util::Collection::Formatter; | ||||||||||||
| 2 | 32 | ▶ | use Mojo::Base -base; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | |||||||||||||
| 4 | 32 | our $VERSION = '0.0.19'; | |||||||||||
| 5 | |||||||||||||
| 6 | 32 | ▶ | use Mojo::JSON qw(encode_json); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | =head2 asOptions | ||||||||||||
| 9 | |||||||||||||
| 10 | Return an array ref containing [{ value => $value, label => $label }, ...] | ||||||||||||
| 11 | |||||||||||||
| 12 | =cut | ||||||||||||
| 13 | |||||||||||||
| 14 | 2 | ▶ | sub asOptions { | ||||||||||
|
Subroutine
asOptions: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 15 | 2 | my ($self, $objects, $value, $label, $value_name, $label_name) = @_; | |||||||||||
| 16 | |||||||||||||
| 17 | 2 | ▶ | $value_name ||= 'value'; | ||||||||||
|
Condition100%2/2
$value_name ||= "value"
MC/DC100%1/1
$value_name ||= "value"
$value_name
Truth table100%2/2
A
A= $value_name
| |||||||||||||
| 18 | 2 | ▶ | $label_name ||= 'label'; | ||||||||||
|
Condition100%2/2
$label_name ||= "label"
MC/DC100%1/1
$label_name ||= "label"
$label_name
Truth table100%2/2
A
A= $label_name
| |||||||||||||
| 19 | |||||||||||||
| 20 | my $options = [map { | ||||||||||||
| 21 | 2 | { | |||||||||||
| 22 | 8 | $value_name => $_->get($value), | |||||||||||
| 23 | $label_name => $_->get($label), | ||||||||||||
| 24 | } | ||||||||||||
| 25 | } @$objects ]; | ||||||||||||
| 26 | |||||||||||||
| 27 | 2 | return $options; | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | =head2 toArray | ||||||||||||
| 31 | |||||||||||||
| 32 | Convert objects to array ref | ||||||||||||
| 33 | |||||||||||||
| 34 | =cut | ||||||||||||
| 35 | |||||||||||||
| 36 | 4 | ▶ | sub toArray { | ||||||||||
|
Subroutine
toArray: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 37 | 4 | my ($self, $objects) = (shift, shift); | |||||||||||
| 38 | |||||||||||||
| 39 | 4 | return [map { $_->serialize(@_) } @$objects]; | |||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | =head2 toCsv | ||||||||||||
| 43 | |||||||||||||
| 44 | Convert objects to CSV string | ||||||||||||
| 45 | |||||||||||||
| 46 | =cut | ||||||||||||
| 47 | |||||||||||||
| 48 | 1 | ▶ | sub toCsv { | ||||||||||
|
Subroutine
toCsv: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 49 | 1 | my ($self, $objects, $header, $columns, $options) = @_; | |||||||||||
| 50 | |||||||||||||
| 51 | 1 | my @array = map { $_->toCsv($columns, $options) } @$objects; | |||||||||||
| 52 | |||||||||||||
| 53 | 1 | ▶ | unshift(@array, $header) if ($header); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | |||||||||||||
| 55 | 1 | return join("\n", @array); | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | =head2 toJson | ||||||||||||
| 59 | |||||||||||||
| 60 | Convert collection to JSON string | ||||||||||||
| 61 | |||||||||||||
| 62 | =cut | ||||||||||||
| 63 | |||||||||||||
| 64 | 2 | ▶ | sub toJson { | ||||||||||
|
Subroutine
toJson: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 65 | 2 | my $self = shift; | |||||||||||
| 66 | |||||||||||||
| 67 | 2 | return encode_json($self->toArray(@_)); | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | 32 | 1; | |||||||||||