Use MooseX::Types::ISO8601 coercion behaviour without the coercion.
[catagits/Gitalist.git] / lib / Gitalist / Git / Types.pm
CommitLineData
ceef0cf1 1package Gitalist::Git::Types;
2
3use MooseX::Types
5c07fcf1 4 -declare => [qw/
5 SHA1
5c07fcf1 6 Dir
ea772511 7 ArrayRefOfDirs
8 DirOrUndef
5c07fcf1 9 /];
ceef0cf1 10
5c07fcf1 11use MooseX::Types::Path::Class;
12use MooseX::Types::ISO8601 qw/ISO8601DateTimeStr/;
f9baba96 13use MooseX::Types::DateTime qw/ DateTime /;
5c07fcf1 14use MooseX::Storage::Engine ();
ceef0cf1 15use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
ea772511 16use MooseX::Types::Moose qw/ ArrayRef Undef Str /;
17use Path::Class qw/ dir /;
ceef0cf1 18
19subtype SHA1,
20 as NonEmptySimpleStr,
21 where { $_ =~ qr/^[0-9a-fA-F]{40}$/ },
22 message { q/Str doesn't look like a SHA1./ };
23
24coerce SHA1,
25 from NonEmptySimpleStr,
26 via { 1 };
27
5c07fcf1 28MooseX::Storage::Engine->add_custom_type_handler(
29 DateTime,
30 expand => sub {
31 my $val = shift;
32 Carp::confess("Not implemented");
33 },
34 collapse => sub {
1369c148 35 $_[0]->ymd('-') . 'T' . $_[0]->hms(':') . 'Z'
5c07fcf1 36 },
37);
38
39subtype Dir,
40 as 'MooseX::Types::Path::Class::Dir',
41 where { 1 };
42
ea772511 43subtype ArrayRefOfDirs, as ArrayRef[Dir], where { scalar(@$_) >= 1 }, message { "Cannot find repository dir" };
44coerce ArrayRefOfDirs, from NonEmptySimpleStr, via { [ dir($_)->resolve ] };
45coerce ArrayRefOfDirs, from ArrayRef[NonEmptySimpleStr], via { [ map { dir($_)->resolve } @$_ ] };
46
47subtype DirOrUndef, as Dir | Undef;
48coerce DirOrUndef, from Str, via { if ($_) { dir($_) } else { undef }};
49
5c07fcf1 50MooseX::Storage::Engine->add_custom_type_handler(
51 Dir,
52 expand => sub {
53 my $val = shift;
54 Carp::confess("Not implemented");
55 },
56 collapse => sub {
57 shift() . '';
58 },
59);
60
ceef0cf1 611;