1package App::Sqitch::Types;
2
3use 5.010;
4use strict;
5use warnings;
6use utf8;
7use Type::Library 0.040 -base, -declare => qw(
8    Sqitch
9    Engine
10    Target
11    UserName
12    UserEmail
13    Plan
14    Change
15    ChangeList
16    LineList
17    Tag
18    Depend
19    DateTime
20    URI
21    URIDB
22    File
23    Dir
24    Config
25    DBH
26);
27use Type::Utils -all;
28use Types::Standard -types;
29use Locale::TextDomain 1.20 qw(App-Sqitch);
30use App::Sqitch::X qw(hurl);
31use App::Sqitch::Config;
32use Scalar::Util qw(blessed);
33use List::Util qw(first);
34
35# Inherit standard types.
36BEGIN { extends 'Types::Standard' };
37
38class_type Sqitch,     { class => 'App::Sqitch'                     };
39class_type Engine,     { class => 'App::Sqitch::Engine'             };
40class_type Target,     { class => 'App::Sqitch::Target'             };
41class_type Plan,       { class => 'App::Sqitch::Plan'               };
42class_type Change,     { class => 'App::Sqitch::Plan::Change'       };
43class_type ChangeList, { class => 'App::Sqitch::Plan::ChangeList'   };
44class_type LineList,   { class => 'App::Sqitch::Plan::LineList'     };
45class_type Tag,        { class => 'App::Sqitch::Plan::Tag'          };
46class_type Depend,     { class => 'App::Sqitch::Plan::Depend'       };
47class_type DateTime,   { class => 'App::Sqitch::DateTime'           };
48class_type URIDB,      { class => 'URI::db'                         };
49class_type Config      { class => 'App::Sqitch::Config'             };
50class_type File        { class => 'Path::Class::File'               };
51class_type Dir         { class => 'Path::Class::Dir'                };
52class_type DBH         { class => 'DBI::db'                         };
53
54subtype UserName, as Str, where {
55    hurl user => __ 'User name may not contain "<" or start with "["'
56        if /^[[]/ || /</;
57    1;
58};
59
60subtype UserEmail, as Str, where {
61    hurl user => __ 'User email may not contain ">"' if />/;
62    1;
63};
64
65# URI can be URI or URI::Nested.
66declare name => URI, constraint => sub {
67    my $o = $_;
68    return blessed $o && first { $o->isa($_)} qw(URI URI::Nested URI::WithBase)
69};
70
711;
72__END__
73
74=head1 Name
75
76App::Sqitch::Types - Definition of attribute data types
77
78=head1 Synopsis
79
80  use App::Sqitch::Types qw(Bool);
81
82=head1 Description
83
84This module defines data types use in Sqitch object attributes. Supported types
85are:
86
87=over
88
89=item C<Sqitch>
90
91An L<App::Sqitch> object.
92
93=item C<Engine>
94
95An L<App::Sqitch::Engine> object.
96
97=item C<Target>
98
99An L<App::Sqitch::Target> object.
100
101=item C<UserName>
102
103A Sqitch user name.
104
105=item C<UserEmail>
106
107A Sqitch user email address.
108
109=item C<Plan>
110
111A L<Sqitch::App::Plan> object.
112
113=item C<Change>
114
115A L<Sqitch::App::Plan::Change> object.
116
117=item C<ChangeList>
118
119A L<Sqitch::App::Plan::ChangeList> object.
120
121=item C<LineList>
122
123A L<Sqitch::App::Plan::LineList> object.
124
125=item C<Tag>
126
127A L<Sqitch::App::Plan::Tag> object.
128
129=item C<Depend>
130
131A L<Sqitch::App::Plan::Depend> object.
132
133=item C<DateTime>
134
135A L<Sqitch::App::DateTime> object.
136
137=item C<URI>
138
139A L<URI> object.
140
141=item C<URIDB>
142
143A L<URI::db> object.
144
145=item C<File>
146
147A C<Class::Path::File> object.
148
149=item C<Dir>
150
151A C<Class::Path::Dir> object.
152
153=item C<Config>
154
155A L<Sqitch::App::Config> object.
156
157=item C<DBH>
158
159A L<DBI> database handle.
160
161=back
162
163=head1 Author
164
165David E. Wheeler <david@justatheory.com>
166
167=head1 License
168
169Copyright (c) 2012-2015 iovation Inc.
170
171Permission is hereby granted, free of charge, to any person obtaining a copy
172of this software and associated documentation files (the "Software"), to deal
173in the Software without restriction, including without limitation the rights
174to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
175copies of the Software, and to permit persons to whom the Software is
176furnished to do so, subject to the following conditions:
177
178The above copyright notice and this permission notice shall be included in all
179copies or substantial portions of the Software.
180
181THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
182IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
183FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
184AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
185LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
186OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
187SOFTWARE.
188
189=cut
190