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