line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Repl::Spec::Type::PatternType - A parameter guard for strings matching a regular expression.
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
This type guard ensures that a string parameter was passed by the user
|
8
|
|
|
|
|
|
|
matching a specified regular expression.
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 Methods
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=over 4
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=item C
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
A regular expression to which the values must conform.
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=item C
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Parameters: A single expression.
|
23
|
|
|
|
|
|
|
Returns: The string value.
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item C
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SEE ALSO
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
L
|
30
|
|
|
|
|
|
|
L
|
31
|
|
|
|
|
|
|
L
|
32
|
|
|
|
|
|
|
L
|
33
|
|
|
|
|
|
|
L
|
34
|
|
|
|
|
|
|
L
|
35
|
|
|
|
|
|
|
L
|
36
|
|
|
|
|
|
|
L
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
package Repl::Spec::Type::PatternType;
|
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
43
|
1
|
|
|
1
|
|
4
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
44
|
1
|
|
|
1
|
|
4
|
use Carp;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
294
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Parameter:
|
47
|
|
|
|
|
|
|
# - A string representing a regexp (don't include the '/').
|
48
|
|
|
|
|
|
|
sub new
|
49
|
|
|
|
|
|
|
{
|
50
|
1
|
|
|
1
|
1
|
7
|
my $invocant = shift;
|
51
|
1
|
|
33
|
|
|
8
|
my $class = ref($invocant) || $invocant;
|
52
|
1
|
|
|
|
|
7
|
my $description = shift;
|
53
|
1
|
|
|
|
|
1
|
my $pattern = shift;
|
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
4
|
my $self= {DESCRIPTION=>$description, PATTERN=>$pattern};
|
56
|
1
|
|
|
|
|
49
|
return bless $self, $class;
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub guard
|
60
|
|
|
|
|
|
|
{
|
61
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
62
|
0
|
|
|
|
|
|
my $arg = shift;
|
63
|
0
|
|
|
|
|
|
my $pattern = $self->{PATTERN};
|
64
|
0
|
|
|
|
|
|
my $description = $self->{DESCRIPTION};
|
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
return $arg if $arg =~ /$pattern/;
|
67
|
0
|
|
|
|
|
|
croak sprintf("Expected '%s' but received '%s'.",$self->name(), $arg);
|
68
|
|
|
|
|
|
|
}
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub name
|
71
|
|
|
|
|
|
|
{
|
72
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
73
|
0
|
|
|
|
|
|
my $pattern = $self->{PATTERN};
|
74
|
0
|
|
|
|
|
|
my $description = $self->{DESCRIPTION};
|
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return sprintf("%s matching /%s/",$description, $pattern);
|
77
|
|
|
|
|
|
|
}
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1;
|