File Coverage

blib/lib/Moose/Exception/AttributeIsRequired.pm
Criterion Covered Total %
statement 11 11 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 2 2 100.0
pod n/a
total 17 18 94.4


line stmt bran cond sub pod time code
1             package Moose::Exception::AttributeIsRequired;
2             our $VERSION = '2.2203';
3              
4 14     14   7678 use Moose;
  14         33  
  14         94  
5             extends 'Moose::Exception';
6             with 'Moose::Exception::Role::Class';
7              
8             has 'attribute_name' => (
9             is => 'ro',
10             isa => 'Str',
11             required => 1,
12             documentation => "This attribute can be used for fetching attribute instance:\n".
13             " my \$class = Moose::Util::find_meta( \$exception->class_name );\n".
14             " my \$attribute = \$class->get_attribute( \$exception->attribute_name );\n",
15             );
16              
17             has 'attribute_init_arg' => (
18             is => 'ro',
19             isa => 'Str',
20             );
21              
22             has 'params' => (
23             is => 'ro',
24             isa => 'HashRef',
25             predicate => 'has_params',
26             );
27              
28             sub _build_message {
29 60     60   105 my $self = shift;
30              
31 60         1672 my $name = $self->attribute_name;
32 60         163 my $msg = "Attribute ($name)";
33              
34 60         1657 my $init_arg = $self->attribute_init_arg;
35 60 100 66     272 if ( defined $init_arg && $name ne $init_arg ) {
36 1         3 $msg .= ", passed as ($init_arg),";
37             }
38              
39 60         159 $msg .= ' is required';
40              
41 60         1229 return $msg;
42             }
43              
44             __PACKAGE__->meta->make_immutable;
45             1;