File Coverage

blib/lib/Specio/Library/Perl.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Specio::Library::Perl;
2              
3 12     12   88 use strict;
  12         25  
  12         401  
4 12     12   76 use warnings;
  12         23  
  12         591  
5              
6             our $VERSION = '0.47';
7              
8 12     12   117 use parent 'Specio::Exporter';
  12         29  
  12         86  
9              
10 12     12   6202 use Specio::Library::String;
  12         49  
  12         89  
11 12     12   6699 use version 0.83 ();
  12         25305  
  12         394  
12              
13 12     12   98 use Specio::Declare;
  12         29  
  12         95  
14              
15             my $package_inline = sub {
16             return sprintf( <<'EOF', $_[0]->parent->inline_check( $_[1] ), $_[1] );
17             (
18             %s
19             &&
20             %s =~ /\A[^\W\d]\w*(?:::\w+)*\z/
21             )
22             EOF
23             };
24              
25             declare(
26             'PackageName',
27             parent => t('NonEmptyStr'),
28             inline => $package_inline,
29             );
30              
31             declare(
32             'ModuleName',
33             parent => t('NonEmptyStr'),
34             inline => $package_inline,
35             );
36              
37             declare(
38             'DistName',
39             parent => t('NonEmptyStr'),
40             inline => sub {
41             return
42             sprintf( <<'EOF', $_[0]->parent->inline_check( $_[1] ), $_[1] );
43             (
44             %s
45             &&
46             %s =~ /\A[^\W\d]\w*(?:-\w+)*\z/
47             )
48             EOF
49             },
50             );
51              
52             declare(
53             'Identifier',
54             parent => t('NonEmptyStr'),
55             inline => sub {
56             return
57             sprintf( <<'EOF', $_[0]->parent->inline_check( $_[1] ), $_[1] );
58             (
59             %s
60             &&
61             %s =~ /\A[^\W\d]\w*\z/
62             )
63             EOF
64             },
65             );
66              
67             declare(
68             'SafeIdentifier',
69             parent => t('Identifier'),
70             inline => sub {
71             return
72             sprintf( <<'EOF', $_[0]->parent->inline_check( $_[1] ), $_[1] );
73             (
74             %s
75             &&
76             %s !~ /\A[_ab]\z/
77             )
78             EOF
79             },
80             );
81              
82             declare(
83             'LaxVersionStr',
84             parent => t('NonEmptyStr'),
85             inline => sub {
86             return
87             sprintf( <<'EOF', $_[0]->parent->inline_check( $_[1] ), $_[1] );
88             (
89             %s
90             &&
91             version::is_lax(%s)
92             )
93             EOF
94             },
95             );
96              
97             declare(
98             'StrictVersionStr',
99             parent => t('NonEmptyStr'),
100             inline => sub {
101             return
102             sprintf( <<'EOF', $_[0]->parent->inline_check( $_[1] ), $_[1] );
103             (
104             %s
105             &&
106             version::is_strict(%s)
107             )
108             EOF
109             },
110             );
111              
112             1;
113              
114             # ABSTRACT: Implements type constraint objects for some common Perl language things
115              
116             __END__
117              
118             =pod
119              
120             =encoding UTF-8
121              
122             =head1 NAME
123              
124             Specio::Library::Perl - Implements type constraint objects for some common Perl language things
125              
126             =head1 VERSION
127              
128             version 0.47
129              
130             =head1 DESCRIPTION
131              
132             This library provides some additional string types for common cases.
133              
134             =head2 PackageName
135              
136             A valid package name. Unlike the C<ClassName> constraint from the
137             L<Specio::Library::Builtins> library, this package does not need to be loaded.
138              
139             This type does allow Unicode characters.
140              
141             =head2 ModuleName
142              
143             Same as C<PackageName>.
144              
145             =head2 DistName
146              
147             A valid distribution name like C<DBD-Pg> Basically this is the same as a
148             package name with the double-colons replaced by dashes. Note that there are
149             some historical distribution names that don't fit this pattern, like C<CGI.pm>.
150              
151             This type does allow Unicode characters.
152              
153             =head2 Identifier
154              
155             An L<Identifier|perldata/Variable names> is something that could be used as a
156             symbol name or other identifier (filehandle, directory handle, subroutine name,
157             format name, or label). It's what you put after the sigil (dollar sign, at
158             sign, percent sign) in a variable name. Generally, it's a bunch of word
159             characters not starting with a digit.
160              
161             This type does allow Unicode characters.
162              
163             =head2 SafeIdentifier
164              
165             This is just like an C<Identifier> but it excludes the single-character
166             variables underscore (C<_>), C<a>< and C<b>, as these are special variables to
167             the Perl interpreter.
168              
169             =head2 LaxVersionStr and StrictVersionStr
170              
171             Lax and strict version strings use the L<is_lax|version/is_lax> and
172             L<is_strict|version/is_strict> methods from C<version> to check if the given
173             string would be a valid lax or strict version. L<version::Internals> covers the
174             details but basically: lax versions are everything you may do, and strict omit
175             many of the usages best avoided.
176              
177             =head2 CREDITS
178              
179             Much of the code and docs for this library comes from MooseX::Types::Perl,
180             written by Ricardo SIGNES <rjbs@cpan.org>.
181              
182             =head1 SUPPORT
183              
184             Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>.
185              
186             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
187              
188             =head1 SOURCE
189              
190             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
191              
192             =head1 AUTHOR
193              
194             Dave Rolsky <autarch@urth.org>
195              
196             =head1 COPYRIGHT AND LICENSE
197              
198             This software is Copyright (c) 2012 - 2021 by Dave Rolsky.
199              
200             This is free software, licensed under:
201              
202             The Artistic License 2.0 (GPL Compatible)
203              
204             The full text of the license can be found in the
205             F<LICENSE> file included with this distribution.
206              
207             =cut