| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PkgForge::Types; # -*-perl-*- |
|
2
|
1
|
|
|
1
|
|
1118
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
34
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
47
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# $Id: Types.pm.in 16978 2011-05-04 11:32:43Z squinney@INF.ED.AC.UK $ |
|
6
|
|
|
|
|
|
|
# $Source:$ |
|
7
|
|
|
|
|
|
|
# $Revision: 16978 $ |
|
8
|
|
|
|
|
|
|
# $HeadURL: https://svn.lcfg.org/svn/source/tags/PkgForge/PkgForge_1_4_8/lib/PkgForge/Types.pm.in $ |
|
9
|
|
|
|
|
|
|
# $Date: 2011-05-04 12:32:43 +0100 (Wed, 04 May 2011) $ |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.4.8'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
1083
|
use Email::Address (); |
|
|
1
|
|
|
|
|
37863
|
|
|
|
1
|
|
|
|
|
65
|
|
|
14
|
1
|
|
|
1
|
|
1067
|
use Email::Valid (); |
|
|
1
|
|
|
|
|
179575
|
|
|
|
1
|
|
|
|
|
60
|
|
|
15
|
1
|
|
|
1
|
|
13
|
use File::Spec (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1996
|
use Moose::Util::TypeConstraints; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use MooseX::Getopt; |
|
19
|
|
|
|
|
|
|
use MooseX::Types -declare => [ 'AbsolutePath', 'AbsolutePathDirectory', |
|
20
|
|
|
|
|
|
|
'EmailAddress', 'EmailAddressList', |
|
21
|
|
|
|
|
|
|
'NoCommas', 'PkgForgeList', |
|
22
|
|
|
|
|
|
|
'UserName', 'UID', 'Octal', |
|
23
|
|
|
|
|
|
|
'SourcePackage', 'SourcePackageList', |
|
24
|
|
|
|
|
|
|
'SourceBuilder', 'PkgForgeID' ]; |
|
25
|
|
|
|
|
|
|
use MooseX::Types::Moose qw(Int Str ArrayRef); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
subtype SourcePackage, |
|
28
|
|
|
|
|
|
|
as role_type('PkgForge::Source'); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
subtype SourcePackageList, |
|
31
|
|
|
|
|
|
|
as ArrayRef[SourcePackage]; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
subtype SourceBuilder, |
|
34
|
|
|
|
|
|
|
as role_type('PkgForge::Builder'); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
subtype AbsolutePath, |
|
37
|
|
|
|
|
|
|
as Str, |
|
38
|
|
|
|
|
|
|
where { File::Spec->file_name_is_absolute($_) }, |
|
39
|
|
|
|
|
|
|
message { 'Must be an absolute path.' }; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# coerce the input string (which is possibly a relative path) into an |
|
42
|
|
|
|
|
|
|
# absolute path which does not have a trailing / |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
coerce AbsolutePath, |
|
45
|
|
|
|
|
|
|
from Str, |
|
46
|
|
|
|
|
|
|
via { my $path = File::Spec->file_name_is_absolute($_) ? $_ : File::Spec->rel2abs($_); $path =~ s{/$}{}; $path }; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
subtype AbsolutePathDirectory, |
|
49
|
|
|
|
|
|
|
as AbsolutePath, |
|
50
|
|
|
|
|
|
|
where { -d $_ }, |
|
51
|
|
|
|
|
|
|
message { 'Must be an absolute path and a directory' }; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
coerce AbsolutePathDirectory, |
|
54
|
|
|
|
|
|
|
from Str, |
|
55
|
|
|
|
|
|
|
via { my $path = File::Spec->file_name_is_absolute($_) ? $_ : File::Spec->rel2abs($_); $path =~ s{/$}{}; $path }; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
subtype EmailAddress, |
|
58
|
|
|
|
|
|
|
as Str, |
|
59
|
|
|
|
|
|
|
where { Email::Valid->address( -address => $_ ) }, |
|
60
|
|
|
|
|
|
|
message { "Address ($_) for report must be a valid email address" }; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
subtype EmailAddressList, as ArrayRef[EmailAddress]; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
coerce EmailAddressList, from Str, via { [ map { $_->format } Email::Address->parse($_)] }; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
coerce EmailAddressList, from ArrayRef, |
|
67
|
|
|
|
|
|
|
via { [ map { $_->format } map { Email::Address->parse($_) } @{$_} ] }; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
subtype UserName, |
|
70
|
|
|
|
|
|
|
as Str, |
|
71
|
|
|
|
|
|
|
where { !/^\d+$/ }; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
coerce UserName, |
|
74
|
|
|
|
|
|
|
from Str, |
|
75
|
|
|
|
|
|
|
via { getpwuid($_) }; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
subtype UID, |
|
78
|
|
|
|
|
|
|
as Int, |
|
79
|
|
|
|
|
|
|
message { "$_ is not a UID" }; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
coerce UID, |
|
82
|
|
|
|
|
|
|
from Str, |
|
83
|
|
|
|
|
|
|
via { getpwnam($_) }; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
subtype Octal, |
|
86
|
|
|
|
|
|
|
as Str, |
|
87
|
|
|
|
|
|
|
where { m/^0\d*$/ }; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# This is all so we can supply a referemce to a list where some |
|
90
|
|
|
|
|
|
|
# elements may contain a comma-separated list and everything will be |
|
91
|
|
|
|
|
|
|
# expanded. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
subtype NoCommas, |
|
94
|
|
|
|
|
|
|
as Str, |
|
95
|
|
|
|
|
|
|
where { !m/,/ }, |
|
96
|
|
|
|
|
|
|
message { "$_ must not contain any commas" }; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
subtype PkgForgeList, |
|
99
|
|
|
|
|
|
|
as ArrayRef[NoCommas]; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
coerce PkgForgeList, |
|
102
|
|
|
|
|
|
|
from ArrayRef, |
|
103
|
|
|
|
|
|
|
via { return [ map { split /\s*,\s*/, $_ } @{$_} ] }; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
coerce PkgForgeList, |
|
106
|
|
|
|
|
|
|
from Str, |
|
107
|
|
|
|
|
|
|
via { return [ split /\s*,\s*/, $_ ] }; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
subtype PkgForgeID, |
|
110
|
|
|
|
|
|
|
as Str, |
|
111
|
|
|
|
|
|
|
where { m/^[A-Za-z0-9_.-]+$/ }, |
|
112
|
|
|
|
|
|
|
message { 'Identifier can only contain characters matching [A-Za-z0-9_-]' }; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
|
115
|
|
|
|
|
|
|
__END__ |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 NAME |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
PkgForge::Types - Moose types for the LCFG Package Forge |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 VERSION |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This documentation refers to PkgForge::Types version 1.4.8 |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
use PkgForge::Types qw(AbsolutePathDirectory); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
has 'directory' => ( |
|
130
|
|
|
|
|
|
|
is => 'rw', |
|
131
|
|
|
|
|
|
|
isa => AbsolutePathDirectory, |
|
132
|
|
|
|
|
|
|
coerce => 1, |
|
133
|
|
|
|
|
|
|
required => 1, |
|
134
|
|
|
|
|
|
|
default => sub { File::Spec->curdir() }, |
|
135
|
|
|
|
|
|
|
); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This module provides various useful Moose types and associated |
|
140
|
|
|
|
|
|
|
coercions that are needed in the LCFG Package Forge suite. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 TYPES |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over 4 |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item AbsolutePath |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
A type based on the Moose string type (Str) which requires it to be an |
|
149
|
|
|
|
|
|
|
absolute path. There is an associated coercion which can be used to |
|
150
|
|
|
|
|
|
|
promote a relative path to an absolute path. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item AbsolutePathDirectory |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
A type based on the AbsolutePath type which also requires it to be a |
|
155
|
|
|
|
|
|
|
directory. Again there is an associated coercion to promote a relative |
|
156
|
|
|
|
|
|
|
path to absolute. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item EmailAddress |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
A type based on the Moose string type (Str) which requires it to be a |
|
161
|
|
|
|
|
|
|
valid email address. The L<Email::Valid> module is required to do the |
|
162
|
|
|
|
|
|
|
validation. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item EmailAddressList |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This list type is based on the Moose ArrayRef type with the |
|
167
|
|
|
|
|
|
|
requirement that all elements are of the C<EmailAddress> type. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item UserName |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This is a string type which represents a user name. Anything which is |
|
172
|
|
|
|
|
|
|
NOT just a sequence of digits (i.e. looks like a UID) will be |
|
173
|
|
|
|
|
|
|
allowed. If a UID is passed in it will be passed through the |
|
174
|
|
|
|
|
|
|
C<getpwuid> function to retrieve the associated username. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item UID |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This is an integer type which represents a user ID (UID). Anything |
|
179
|
|
|
|
|
|
|
which is not an integer will be passed through the C<getpwnam> |
|
180
|
|
|
|
|
|
|
function to retrieve the associated UID. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item Octal |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This is a string type which represents an octal number. It expects the |
|
185
|
|
|
|
|
|
|
string to start with a zero followed by a sequence of digits. This is |
|
186
|
|
|
|
|
|
|
aimed at attributes which represent Unix file permission modes. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item NoCommas |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This type is based on the Moose string type (Str) which requires that |
|
191
|
|
|
|
|
|
|
the string does not contain any commas. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item PkgForgeList |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This type is based on the Moose ArrayRef type with the requirement |
|
196
|
|
|
|
|
|
|
that each element is of the C<NoCommas> type. The interesting aspect |
|
197
|
|
|
|
|
|
|
of this type is the associated coercions from Str and ArrayRef |
|
198
|
|
|
|
|
|
|
types. When coercing from a string it will be split on commas and the |
|
199
|
|
|
|
|
|
|
resulting list will be used. When coercing from a list each element |
|
200
|
|
|
|
|
|
|
will be passed through the same string coercion to split on commas. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=back |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This module does not provide any subroutines or methods. |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
This module is L<Moose> powered and uses L<MooseX::Types>. It also |
|
211
|
|
|
|
|
|
|
requires L<Email::Address> and L<Email::Valid>. |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L<PkgForge> |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 PLATFORMS |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
This is the list of platforms on which we have tested this |
|
220
|
|
|
|
|
|
|
software. We expect this software to work on any Unix-like platform |
|
221
|
|
|
|
|
|
|
which is supported by Perl. |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
ScientificLinux5, Fedora13 |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Please report any bugs or problems (or praise!) to bugs@lcfg.org, |
|
228
|
|
|
|
|
|
|
feedback and patches are also always very welcome. |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 AUTHOR |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Stephen Quinney <squinney@inf.ed.ac.uk> |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Copyright (C) 2010-2011 University of Edinburgh. All rights reserved. |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
239
|
|
|
|
|
|
|
it under the terms of the GPL, version 2 or later. |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |