File Coverage

blib/lib/MooseX/Attribute/Dependent/Meta/Role/Class.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             #
2             # This file is part of MooseX-Attribute-Dependent
3             #
4             # This software is Copyright (c) 2011 by Moritz Onken.
5             #
6             # This is free software, licensed under:
7             #
8             # The (three-clause) BSD License
9             #
10             package MooseX::Attribute::Dependent::Meta::Role::Class;
11             {
12             $MooseX::Attribute::Dependent::Meta::Role::Class::VERSION = '1.1.2';
13             }
14              
15 3     3   10433 use strict;
  3         6  
  3         113  
16 3     3   23 use warnings;
  3         6  
  3         86  
17 3     3   18 use Moose::Role;
  3         6  
  3         24  
18              
19             override _inline_check_required_attr => sub {
20             my ($self, $attr, $idx) = @_;
21             return super()
22             if(!$attr->does('MooseX::Attribute::Dependent::Meta::Role::Attribute')
23             || !$attr->has_dependency
24             || !$attr->init_arg);
25             my @source;
26             my $related = "'" . join("', '", @{$attr->dependency->parameters}) . "'";
27             push @source => 'if(exists $params->{' . $attr->init_arg . '}) {';
28             push @source => $self->_inline_throw_error( '"' . quotemeta($attr->dependency->get_message) . '"' );
29             push @source => "unless(" . $attr->dependency->name . "->constraint->(\"" . quotemeta($attr->init_arg) . "\", \$params, $related));";
30             push @source => '}';
31             return join("\n", @source, super());
32             };
33              
34              
35             1;
36             __END__
37             =pod
38              
39             =head1 NAME
40              
41             MooseX::Attribute::Dependent::Meta::Role::Class
42              
43             =head1 VERSION
44              
45             version 1.1.2
46              
47             =head1 AUTHOR
48              
49             Moritz Onken
50              
51             =head1 COPYRIGHT AND LICENSE
52              
53             This software is Copyright (c) 2011 by Moritz Onken.
54              
55             This is free software, licensed under:
56              
57             The (three-clause) BSD License
58              
59             =cut
60