| 1 | package FormValidator::Simple::Data; | ||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 9 | ▶ | use Scalar::Util; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 9 | ▶ | use FormValidator::Simple::Exception; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 9 | ▶ | use FormValidator::Simple::Constants; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 8 | 0 | my $class = shift; | |||||||||||||
| 9 | 0 | my $self = bless { }, $class; | |||||||||||||
| 10 | 0 | $self->_init(@_); | |||||||||||||
| 11 | 0 | return $self; | |||||||||||||
| 12 | } | ||||||||||||||
| 13 | |||||||||||||||
| 14 | 0 | ▶ | sub _init { | ||||||||||||
|
Subroutine
_init: not called CC=6 SCAR=37.4
| |||||||||||||||
| 15 | 0 | my ($self, $input) = @_; | |||||||||||||
| 16 | 0 | $self->{_records} = {}; | |||||||||||||
| 17 | 0 | my $errmsg = qq/Set input data as a hashref or object that has the method 'param()'./; | |||||||||||||
| 18 | 0 | ▶ | if ( Scalar::Util::blessed($input) ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 19 | 0 | ▶ | unless ( $input->can('param') ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | 0 | FormValidator::Simple::Exception->throw($errmsg); | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | 0 | foreach my $key ( $input->param ) { | |||||||||||||
| 23 | 0 | my @v = $input->param($key); | |||||||||||||
| 24 | 0 | ▶ | $self->{_records}{$key} = scalar(@v) > 1 ? \@v : $v[0]; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | } | ||||||||||||||
| 26 | } | ||||||||||||||
| 27 | elsif ( ref $input eq 'HASH' ) { | ||||||||||||||
| 28 | 0 | $self->{_records} = $input; | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | else { | ||||||||||||||
| 31 | 0 | FormValidator::Simple::Exception->throw($errmsg); | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | ▶ | sub has_key { | ||||||||||||
|
Subroutine
has_key: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 36 | 0 | my ($self, $key) = @_; | |||||||||||||
| 37 | 0 | ▶ | return exists $self->{_records}{$key} ? TRUE : FALSE; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 0 | ▶ | sub param { | ||||||||||||
|
Subroutine
param: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 41 | 0 | my ($self, $keys) = @_; | |||||||||||||
| 42 | my @values = map { | ||||||||||||||
| 43 | 0 | exists $self->{_records}{$_} | |||||||||||||
| 44 | 0 | ▶ | ? $self->{_records}{$_} | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | : '' | ||||||||||||||
| 46 | ; | ||||||||||||||
| 47 | } @$keys; | ||||||||||||||
| 48 | 0 | ▶ | return wantarray ? @values : \@values; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 9 | 1; | |||||||||||||
| 52 | __END__ | ||||||||||||||