File: ValidationFailedForInlineTypeConstraint.pm

package info (click to toggle)
libmoose-perl 2.4000-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,408 kB
  • sloc: perl: 21,275; ansic: 291; makefile: 10
file content (49 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package Moose::Exception::ValidationFailedForInlineTypeConstraint;
our $VERSION = '2.4000';

use Moose;
extends 'Moose::Exception';
with 'Moose::Exception::Role::Class';

has 'type_constraint_message' => (
    is       => 'ro',
    isa      => 'Str',
    required => 1
);

has 'attribute_name' => (
    is       => 'ro',
    isa      => 'Str',
    required => 1
);

has 'value' => (
    is       => 'ro',
    isa      => 'Any',
    required => 1
);

has 'new_member' => (
    is        => 'ro',
    isa       => 'Bool',
    default   => 0,
    predicate => 'is_a_new_member'
);

sub _build_message {
    my $self = shift;

    my $line1;

    if( $self->new_member ) {
        $line1 = "A new member value for ".$self->attribute_name." does not pass its type constraint because: "
    }
    else {
        $line1 = "Attribute (".$self->attribute_name.") does not pass the type constraint because: ";
    }

    return $line1 . $self->type_constraint_message;
}

__PACKAGE__->meta->make_immutable;
1;