| 1 | package Dancer2::Plugin::FormValidator::Factory::Messages; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 16 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 16 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 16 | ▶ | use Hash::MultiValue; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 16 | ▶ | use Types::Standard qw(InstanceOf ConsumerOf); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 16 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 16 | has config => ( | |||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||
| 14 | isa => InstanceOf['Dancer2::Plugin::FormValidator::Config'], | ||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 16 | has registry => ( | |||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||
| 20 | isa => InstanceOf['Dancer2::Plugin::FormValidator::Registry'], | ||||||||||||||||||||
| 21 | required => 1, | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | # Generates messages for each invalid field. | ||||||||||||||||||||
| 25 | sub build { | ||||||||||||||||||||
| 26 | 14 | ▶ | my ($self, $invalid, $profile_messages) = @_; | ||||||||||||||||||
|
Subroutine
build: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 14 | my $messages = Hash::MultiValue->new; | |||||||||||||||||||
| 29 | 14 | my $config = $self->config; | |||||||||||||||||||
| 30 | 14 | my $ucfirst = $config->ucfirst; | |||||||||||||||||||
| 31 | 14 | my $language = $config->language; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 14 | for my $item (@{ $invalid }) { | |||||||||||||||||||
| 34 | 23 | my ($field, $name, $params) = @$item; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 23 | my $validator = $self->registry->get($name); | |||||||||||||||||||
| 37 | 23 | ▶ | my $message = $self->config->messages_validators->{$name} || $validator->message; | ||||||||||||||||||
|
Condition66%2/3
$self->config->messages_validators->{$name} || $validator->message
MC/DC0%0/2
$self->config->messages_validators->{$name} || $validator->message
$self->config->messages_validators->{$name}
$validator->message
Truth table66%2/3
A || B
A= $self->config->messages_validators->{$name}B= $validator->message
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 23 | ▶ | if (defined $profile_messages) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 6 | ▶ | if (ref $profile_messages ne 'HASH') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 0 | Carp::croak("Messages should be a HashRef\n") | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 6 | ▶ | $message = $profile_messages->{$field}->{$name} || $message; | ||||||||||||||||||
|
Condition66%2/3
$profile_messages->{$field}{$name} || $message
MC/DC0%0/2
$profile_messages->{$field}{$name} || $message
$profile_messages->{$field}{$name}
$message
Truth table66%2/3
A || B
A= $profile_messages->{$field}{$name}B= $message
| |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # Create and add message. | ||||||||||||||||||||
| 48 | { | ||||||||||||||||||||
| 49 | # Cause we need this feature. | ||||||||||||||||||||
| 50 | 16 | ▶ | no warnings 'redundant'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | $messages->add( | ||||||||||||||||||||
| 53 | $field, | ||||||||||||||||||||
| 54 | sprintf( | ||||||||||||||||||||
| 55 | 23 | ▶ | $message->{$language}, | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | $ucfirst ? ucfirst($field) : $field, | ||||||||||||||||||||
| 57 | split(',', $params), | ||||||||||||||||||||
| 58 | ) | ||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 14 | return $messages->as_hashref_multi; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 16 | 1; | |||||||||||||||||||