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