| 1 | =head1 NAME | ||||||||||||
| 2 | |||||||||||||
| 3 | Declare::Constraints::Simple::Result - Validation Result | ||||||||||||
| 4 | |||||||||||||
| 5 | =cut | ||||||||||||
| 6 | |||||||||||||
| 7 | package Declare::Constraints::Simple::Result; | ||||||||||||
| 8 | 14 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 14 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | use overload | ||||||||||||
| 12 | 14 | ▶ | bool => \&is_valid, | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 14 | fallback => 1; | |||||||||||
| 14 | |||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||
| 16 | |||||||||||||
| 17 | my $result = $constraint->($value); | ||||||||||||
| 18 | |||||||||||||
| 19 | my $message = $result->message; | ||||||||||||
| 20 | my $path = $result->path; | ||||||||||||
| 21 | |||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||
| 23 | |||||||||||||
| 24 | This represents a result returned by a L<Declare::Constraints::Simple> | ||||||||||||
| 25 | constraint. Objects of this kind overload their boolean context, so the | ||||||||||||
| 26 | value of the L<is_valid()> accessor is reflected to it. | ||||||||||||
| 27 | |||||||||||||
| 28 | =cut | ||||||||||||
| 29 | |||||||||||||
| 30 | 14 | my %init = ( | |||||||||||
| 31 | message => '', | ||||||||||||
| 32 | valid => 0, | ||||||||||||
| 33 | ); | ||||||||||||
| 34 | |||||||||||||
| 35 | =head1 METHODS | ||||||||||||
| 36 | |||||||||||||
| 37 | =head2 new() | ||||||||||||
| 38 | |||||||||||||
| 39 | Constructor. As you will mostly just receive result objects, you should | ||||||||||||
| 40 | never be required to call this yourself. | ||||||||||||
| 41 | |||||||||||||
| 42 | =cut | ||||||||||||
| 43 | |||||||||||||
| 44 | 605 | ▶ | sub new { bless {%init, stack => []} => shift } | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 45 | |||||||||||||
| 46 | =head2 set_valid($bool) | ||||||||||||
| 47 | |||||||||||||
| 48 | Sets the results validity flag. | ||||||||||||
| 49 | |||||||||||||
| 50 | =head2 is_valid() | ||||||||||||
| 51 | |||||||||||||
| 52 | Boolean accessor telling if this is a true result or not. | ||||||||||||
| 53 | |||||||||||||
| 54 | =cut | ||||||||||||
| 55 | |||||||||||||
| 56 | 605 | ▶ | sub set_valid { $_[0]->{valid} = $_[1] } | ||||||||||
|
Subroutine
set_valid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 57 | 1892 | ▶ | sub is_valid { shift->{valid} } | ||||||||||
|
Subroutine
is_valid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 58 | |||||||||||||
| 59 | =head2 set_message($message) | ||||||||||||
| 60 | |||||||||||||
| 61 | The error message. Useful only on non-valid results. | ||||||||||||
| 62 | |||||||||||||
| 63 | =head2 message() | ||||||||||||
| 64 | |||||||||||||
| 65 | Returns the message of the result object. | ||||||||||||
| 66 | |||||||||||||
| 67 | =cut | ||||||||||||
| 68 | |||||||||||||
| 69 | 159 | ▶ | sub set_message { $_[0]->{message} = $_[1] } | ||||||||||
|
Subroutine
set_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 70 | 12 | ▶ | sub message { shift->{message} } | ||||||||||
|
Subroutine
message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 71 | |||||||||||||
| 72 | =head2 add_to_stack($constraint_name) | ||||||||||||
| 73 | |||||||||||||
| 74 | This adds another level at the beginning (!) of the results constraint | ||||||||||||
| 75 | stack. This is mostly intended to use for the C<prepare_generator>method | ||||||||||||
| 76 | in L<Declare::Constraints::Simple::Library> package. | ||||||||||||
| 77 | |||||||||||||
| 78 | =head2 path([$separator]) | ||||||||||||
| 79 | |||||||||||||
| 80 | Returns a string containing the L<stack()> contents joined together by | ||||||||||||
| 81 | the C<$separator> string (defaulting to C<.>). | ||||||||||||
| 82 | |||||||||||||
| 83 | =cut | ||||||||||||
| 84 | |||||||||||||
| 85 | 238 | ▶ | sub add_to_stack { unshift @{shift->{stack}}, shift } | ||||||||||
|
Subroutine
add_to_stack: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 86 | 17 | ▶ | sub path { join( ($_[1]||'.'), @{$_[0]->stack} ) } | ||||||||||
|
Subroutine
path: called CC=2 SCAR=7.2
Pod
documented
Condition50%1/2
$_[1] || '.'
MC/DC0%0/1
$_[1] || '.'
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||
| 87 | |||||||||||||
| 88 | =head2 stack() | ||||||||||||
| 89 | |||||||||||||
| 90 | Returns an array reference containing the results currrent stack. This | ||||||||||||
| 91 | is a list of the constraints path parts. This is usually just the | ||||||||||||
| 92 | constraints name. If there's additional info, it is appended to the | ||||||||||||
| 93 | name like C<[$info]>. | ||||||||||||
| 94 | |||||||||||||
| 95 | =cut | ||||||||||||
| 96 | |||||||||||||
| 97 | 17 | ▶ | sub stack { $_[0]->{stack} } | ||||||||||
|
Subroutine
stack: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 98 | |||||||||||||
| 99 | =head1 SEE ALSO | ||||||||||||
| 100 | |||||||||||||
| 101 | L<Declare::Constraints::Simple> | ||||||||||||
| 102 | |||||||||||||
| 103 | =head1 AUTHOR | ||||||||||||
| 104 | |||||||||||||
| 105 | Robert 'phaylon' Sedlacek C<E<lt>phaylon@dunkelheit.atE<gt>> | ||||||||||||
| 106 | |||||||||||||
| 107 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 108 | |||||||||||||
| 109 | This module is free software, you can redistribute it and/or modify it | ||||||||||||
| 110 | under the same terms as perl itself. | ||||||||||||
| 111 | |||||||||||||
| 112 | =cut | ||||||||||||
| 113 | |||||||||||||
| 114 | 14 | 1; | |||||||||||