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