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::Attribute; |
11
|
|
|
|
|
|
|
$MooseX::Attribute::Dependent::Meta::Role::Attribute::VERSION = '1.1.4'; |
12
|
3
|
|
|
3
|
|
27950
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
89
|
|
13
|
3
|
|
|
3
|
|
29
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
88
|
|
14
|
3
|
|
|
3
|
|
16
|
use Moose::Role; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
24
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has dependency => ( predicate => 'has_dependency', is => 'ro' ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
before initialize_instance_slot => sub { |
19
|
|
|
|
|
|
|
my ( $self, $meta_instance, $instance, $params ) = @_; |
20
|
|
|
|
|
|
|
return |
21
|
|
|
|
|
|
|
unless ( exists $params->{ $self->init_arg } |
22
|
|
|
|
|
|
|
&& ( my $dep = $self->dependency ) ); |
23
|
|
|
|
|
|
|
$self->throw_error( $dep->get_message, object => $instance ) |
24
|
|
|
|
|
|
|
unless ( |
25
|
|
|
|
|
|
|
$dep->constraint->( $self->init_arg, $params, @{ $dep->parameters } ) ); |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
around accessor_metaclass => sub { |
29
|
|
|
|
|
|
|
my ($orig) = (shift); |
30
|
|
|
|
|
|
|
my $class = shift->$orig(@_); |
31
|
|
|
|
|
|
|
return Moose::Meta::Class->create_anon_class( |
32
|
|
|
|
|
|
|
superclasses => [$class], |
33
|
|
|
|
|
|
|
roles => ['MooseX::Attribute::Dependent::Meta::Role::Method::Accessor'], |
34
|
|
|
|
|
|
|
cache => 1 |
35
|
|
|
|
|
|
|
)->name; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} if Moose->VERSION < 1.9900; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
around _inline_check_required => sub { |
40
|
|
|
|
|
|
|
my $orig = shift; |
41
|
|
|
|
|
|
|
my $attr = shift; |
42
|
|
|
|
|
|
|
my @code = $attr->$orig(@_); |
43
|
|
|
|
|
|
|
return @code |
44
|
|
|
|
|
|
|
if ( !$attr->does('MooseX::Attribute::Dependent::Meta::Role::Attribute') |
45
|
|
|
|
|
|
|
|| !$attr->has_dependency |
46
|
|
|
|
|
|
|
|| !$attr->init_arg ); |
47
|
|
|
|
|
|
|
my @source; |
48
|
|
|
|
|
|
|
my $related = |
49
|
|
|
|
|
|
|
"'" . join( "', '", @{ $attr->dependency->parameters } ) . "'"; |
50
|
|
|
|
|
|
|
push @source => $attr->_inline_throw_error( |
51
|
|
|
|
|
|
|
'"' . quotemeta( $attr->dependency->get_message ) . '"' ); |
52
|
|
|
|
|
|
|
push @source => "unless(" |
53
|
|
|
|
|
|
|
. $attr->dependency->name |
54
|
|
|
|
|
|
|
. "->constraint->(\"" |
55
|
|
|
|
|
|
|
. quotemeta( $attr->name ) |
56
|
|
|
|
|
|
|
. "\", \$_[0], $related));"; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return join( "\n", @source, @code ); |
59
|
|
|
|
|
|
|
} if Moose->VERSION >= 1.9900; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=pod |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=encoding UTF-8 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
MooseX::Attribute::Dependent::Meta::Role::Attribute |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 VERSION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
version 1.1.4 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Moritz Onken |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Moritz Onken. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This is free software, licensed under: |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The (three-clause) BSD License |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |