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::Dependency; |
11
|
|
|
|
|
|
|
$MooseX::Attribute::Dependency::VERSION = '1.1.4'; |
12
|
4
|
|
|
4
|
|
100692
|
use Moose; |
|
4
|
|
|
|
|
851960
|
|
|
4
|
|
|
|
|
30
|
|
13
|
|
|
|
|
|
|
has [qw(parameters message constraint name)] => ( is => 'ro' ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub get_message { |
16
|
22
|
|
|
22
|
0
|
82
|
my ($self) = @_; |
17
|
22
|
|
|
|
|
624
|
sprintf( $self->message, join( ', ', @{ $self->parameters } ) ); |
|
22
|
|
|
|
|
573
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
4
|
|
|
4
|
|
28623
|
use overload( bool => sub {1} ); |
|
4
|
|
|
55
|
|
11
|
|
|
4
|
|
|
|
|
41
|
|
|
55
|
|
|
|
|
364
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $meta = Class::MOP::Class->initialize('MooseX::Attribute::Dependencies'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub register { |
25
|
17
|
|
|
17
|
0
|
234
|
my ($args) = @_; |
26
|
4
|
|
|
4
|
|
353
|
no strict 'refs'; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
520
|
|
27
|
17
|
|
|
|
|
48
|
my $name = 'MooseX::Attribute::Dependencies::' . $args->{name}; |
28
|
|
|
|
|
|
|
my $code = sub { |
29
|
30
|
|
|
30
|
|
52866
|
my $params = shift; |
|
|
|
|
30
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
1
|
|
|
|
30
|
30
|
|
|
|
|
1044
|
my $dep = MooseX::Attribute::Dependency->new( |
31
|
|
|
|
|
|
|
%$args, |
32
|
|
|
|
|
|
|
name => $name, |
33
|
|
|
|
|
|
|
parameters => $params |
34
|
|
|
|
|
|
|
); |
35
|
30
|
100
|
|
|
|
857
|
return @_ ? ($dep, @_) : $dep; |
36
|
17
|
|
|
|
|
101
|
}; |
37
|
17
|
|
|
|
|
59
|
$meta->add_method( $args->{name}, $code ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
package MooseX::Attribute::Dependencies; |
43
|
|
|
|
|
|
|
$MooseX::Attribute::Dependencies::VERSION = '1.1.4'; |
44
|
4
|
|
|
4
|
|
25
|
use strict; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
78
|
|
45
|
4
|
|
|
4
|
|
45
|
use warnings; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
151
|
|
46
|
4
|
|
|
4
|
|
22
|
use List::Util 1.33 (); |
|
4
|
|
|
|
|
95
|
|
|
4
|
|
|
|
|
1046
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
MooseX::Attribute::Dependency::register( |
49
|
|
|
|
|
|
|
{ name => 'All', |
50
|
|
|
|
|
|
|
message => 'The following attributes are required: %s', |
51
|
|
|
|
|
|
|
constraint => sub { |
52
|
|
|
|
|
|
|
my ( $attr_name, $params, @related ) = @_; |
53
|
|
|
|
|
|
|
return List::Util::all { exists $params->{$_} } @related; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
MooseX::Attribute::Dependency::register( |
59
|
|
|
|
|
|
|
{ name => 'Any', |
60
|
|
|
|
|
|
|
message => 'At least one of the following attributes is required: %s', |
61
|
|
|
|
|
|
|
constraint => sub { |
62
|
|
|
|
|
|
|
my ( $attr_name, $params, @related ) = @_; |
63
|
|
|
|
|
|
|
return List::Util::any { exists $params->{$_} } @related; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
MooseX::Attribute::Dependency::register( |
69
|
|
|
|
|
|
|
{ name => 'None', |
70
|
|
|
|
|
|
|
message => 'None of the following attributes can have a value: %s', |
71
|
|
|
|
|
|
|
constraint => sub { |
72
|
|
|
|
|
|
|
my ( $attr_name, $params, @related ) = @_; |
73
|
|
|
|
|
|
|
return List::Util::none { exists $params->{$_} } @related; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
MooseX::Attribute::Dependency::register( |
79
|
|
|
|
|
|
|
{ name => 'NotAll', |
80
|
|
|
|
|
|
|
message => |
81
|
|
|
|
|
|
|
'At least one of the following attributes cannot have a value: %s', |
82
|
|
|
|
|
|
|
constraint => sub { |
83
|
|
|
|
|
|
|
my ( $attr_name, $params, @related ) = @_; |
84
|
|
|
|
|
|
|
return List::Util::notall { exists $params->{$_} } @related; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=encoding UTF-8 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
MooseX::Attribute::Dependency |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 VERSION |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
version 1.1.4 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Moritz Onken |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Moritz Onken. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software, licensed under: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The (three-clause) BSD License |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |