| 1 | package Catmandu::Fix::count; | ||
| 2 | |||
| 3 | 1 | ▶ | use Catmandu::Sane; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | our $VERSION = '1.0201_02'; | |
| 6 | |||
| 7 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use Catmandu::Fix::Has; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 1 | has path => (fix_arg => 1); | |
| 12 | |||
| 13 | 1 | with 'Catmandu::Fix::SimpleGetValue'; | |
| 14 | |||
| 15 | sub emit_value { | ||
| 16 | 4 | ▶ | my ($self, $var) = @_; |
|
Subroutine
emit_value: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 17 | 4 | "if (is_array_ref(${var})) {" | |
| 18 | . "${var} = scalar \@{${var}};" | ||
| 19 | . "} elsif (is_hash_ref(${var})) {" | ||
| 20 | . "${var} = scalar keys \%{${var}};" . "}"; | ||
| 21 | } | ||
| 22 | |||
| 23 | 1 | 1; | |
| 24 | |||
| 25 | __END__ | ||
| 26 | |||
| 27 | =pod | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | Catmandu::Fix::count - replace the value of an array or hash field with its count | ||
| 32 | |||
| 33 | =head1 SYNOPSIS | ||
| 34 | |||
| 35 | # e.g. tags => ["foo", "bar"] | ||
| 36 | count(tags) # tags => 2 | ||
| 37 | |||
| 38 | =head1 SEE ALSO | ||
| 39 | |||
| 40 | L<Catmandu::Fix> | ||
| 41 | |||
| 42 | =cut | ||