line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Specio::Constraint::Enum; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
100
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.46'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
13
|
use Role::Tiny::With; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
126
|
|
9
|
2
|
|
|
2
|
|
11
|
use Scalar::Util qw( refaddr ); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
87
|
|
10
|
2
|
|
|
2
|
|
13
|
use Specio::Library::Builtins; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
19
|
|
11
|
2
|
|
|
2
|
|
14
|
use Specio::OO; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
121
|
|
12
|
2
|
|
|
2
|
|
14
|
use Storable qw( dclone ); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
95
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
12
|
use Specio::Constraint::Role::Interface; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
777
|
|
15
|
|
|
|
|
|
|
with 'Specio::Constraint::Role::Interface'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
{ |
18
|
|
|
|
|
|
|
## no critic (Subroutines::ProtectPrivateSubs) |
19
|
|
|
|
|
|
|
my $attrs = dclone( Specio::Constraint::Role::Interface::_attrs() ); |
20
|
|
|
|
|
|
|
## use critic |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
for my $name (qw( parent _inline_generator )) { |
23
|
|
|
|
|
|
|
$attrs->{$name}{init_arg} = undef; |
24
|
|
|
|
|
|
|
$attrs->{$name}{builder} |
25
|
|
|
|
|
|
|
= $name =~ /^_/ ? '_build' . $name : '_build_' . $name; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$attrs->{values} = { |
29
|
|
|
|
|
|
|
isa => 'ArrayRef', |
30
|
|
|
|
|
|
|
required => 1, |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
34
|
|
|
|
|
|
|
sub _attrs { |
35
|
4
|
|
|
4
|
|
11
|
return $attrs; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
my $Str = t('Str'); |
41
|
3
|
|
|
3
|
|
19
|
sub _build_parent {$Str} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
my $_inline_generator = sub { |
46
|
|
|
|
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
my $val = shift; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
return sprintf( <<'EOF', ($val) x 2, $self->_env_var_name, $val ); |
50
|
|
|
|
|
|
|
( !ref( %s ) && defined( %s ) && $%s{ %s } ) |
51
|
|
|
|
|
|
|
EOF |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
3
|
|
100
|
sub _build_inline_generator {$_inline_generator} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _build_inline_environment { |
58
|
3
|
|
|
3
|
|
16
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
3
|
|
|
|
|
6
|
my %values = map { $_ => 1 } @{ $self->values }; |
|
9
|
|
|
|
|
31
|
|
|
3
|
|
|
|
|
9
|
|
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
8
|
return { '%' . $self->_env_var_name => \%values }; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _env_var_name { |
66
|
7
|
|
|
7
|
|
12
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
7
|
|
|
|
|
48
|
return '_Specio_Constraint_Enum_' . refaddr($self); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__PACKAGE__->_ooify; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# ABSTRACT: A class for constraints which require a string matching one of a set of values |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=pod |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=encoding UTF-8 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Specio::Constraint::Enum - A class for constraints which require a string matching one of a set of values |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 VERSION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
version 0.46 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SYNOPSIS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $type = Specio::Constraint::Enum->new(...); |
94
|
|
|
|
|
|
|
print $_, "\n" for @{ $type->values }; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DESCRIPTION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This is a specialized type constraint class for types which require a string |
99
|
|
|
|
|
|
|
that matches one of a list of values. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 API |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This class provides all of the same methods as L<Specio::Constraint::Simple>, |
104
|
|
|
|
|
|
|
with a few differences: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 Specio::Constraint::Enum->new( ... ) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
The C<parent> parameter is ignored if it passed, as it is always set to the |
109
|
|
|
|
|
|
|
C<Str> type. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
The C<inline_generator> and C<constraint> parameters are also ignored. This |
112
|
|
|
|
|
|
|
class provides its own default inline generator subroutine reference. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Finally, this class requires an additional parameter, C<values>. This must be a |
115
|
|
|
|
|
|
|
an arrayref of valid strings for the type. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 $enum->values |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns an array reference of valid values for the type. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 ROLES |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This class does the L<Specio::Constraint::Role::Interface> and |
124
|
|
|
|
|
|
|
L<Specio::Role::Inlinable> roles. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SUPPORT |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SOURCE |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This software is Copyright (c) 2012 - 2020 by Dave Rolsky. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This is free software, licensed under: |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The full text of the license can be found in the |
149
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |