| 1 | package Store::Digest::Types; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use MooseX::Types::Moose qw(Maybe Str Int FileHandle HashRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use MooseX::Types -declare => [qw(DateTimeType DigestURI Seekable | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | FiniteHandle DigestHash | ||||||||||
| 14 | NonNegativeInt ContentType RFC3066 | ||||||||||
| 15 | MaybeDateTime MaybeToken | ||||||||||
| 16 | 1 | Token File Directory StoreObject)]; | |||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use DateTime (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use URI::ni (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ▶ | use Path::Class (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | =head1 NAME | ||||||||||
| 23 | |||||||||||
| 24 | Store::Digest::Types - Custom types for Store::Digest; | ||||||||||
| 25 | |||||||||||
| 26 | =head1 VERSION | ||||||||||
| 27 | |||||||||||
| 28 | Version 0.01 | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | 1 | our $VERSION = '0.01'; | |||||||||
| 33 | |||||||||||
| 34 | =head1 SYNOPSIS | ||||||||||
| 35 | |||||||||||
| 36 | package Store::Digest::XYZ; | ||||||||||
| 37 | |||||||||||
| 38 | use Moose; | ||||||||||
| 39 | use namespace::autoclean; | ||||||||||
| 40 | |||||||||||
| 41 | use Store::Digest::Types; | ||||||||||
| 42 | |||||||||||
| 43 | # ... do your thing | ||||||||||
| 44 | |||||||||||
| 45 | =head1 TYPES | ||||||||||
| 46 | |||||||||||
| 47 | =head2 DateTimeType | ||||||||||
| 48 | |||||||||||
| 49 | =cut | ||||||||||
| 50 | |||||||||||
| 51 | 1 | subtype DateTimeType, as class_type('DateTime'); | |||||||||
| 52 | 0 | ▶ | coerce DateTimeType, from Int, via { DateTime->from_epoch(epoch => shift) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 53 | |||||||||||
| 54 | 1 | subtype MaybeDateTime, as Maybe[DateTimeType]; | |||||||||
| 55 | |||||||||||
| 56 | coerce MaybeDateTime, from Maybe[Int], | ||||||||||
| 57 | 0 | ▶ | via { $_[0] ? DateTime->from_epoch(epoch => $_[0]) : undef }; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | =head2 DigestHash | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 1 | subtype DigestURI, as class_type('URI::ni'); | |||||||||
| 64 | |||||||||||
| 65 | 1 | subtype DigestHash, as HashRef[DigestURI]; | |||||||||
| 66 | |||||||||||
| 67 | =head2 FiniteHandle | ||||||||||
| 68 | |||||||||||
| 69 | =cut | ||||||||||
| 70 | |||||||||||
| 71 | 1 | subtype Seekable, as class_type('IO::Seekable'); | |||||||||
| 72 | |||||||||||
| 73 | 1 | subtype FiniteHandle, as FileHandle|Seekable; | |||||||||
| 74 | |||||||||||
| 75 | =head2 File and Directory | ||||||||||
| 76 | |||||||||||
| 77 | These are just labels for L<Path::Class> objects. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | 1 | subtype File, as class_type('Path::Class::File'); | |||||||||
| 82 | 1 | subtype Directory, as class_type('Path::Class::Dir'); | |||||||||
| 83 | |||||||||||
| 84 | 0 | ▶ | coerce File, from Str, via { Path::Class::File->new(shift) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 85 | 0 | ▶ | coerce Directory, from Str, via { Path::Class::Dir->new(shift) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 86 | |||||||||||
| 87 | =head2 Token | ||||||||||
| 88 | |||||||||||
| 89 | A token, as described by L<RFC | ||||||||||
| 90 | 2616|http://tools.ietf.org/html/rfc2616>, section 2.2. | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | # XXX this screws up | ||||||||||
| 95 | #my $bads = quotemeta('()<>@,;:\"/[]?={}'); | ||||||||||
| 96 | #my $token = qr![^\x00-x20\x7f-\xff$bads]+!o; | ||||||||||
| 97 | |||||||||||
| 98 | # XXX this is the above, rewritten, and works. | ||||||||||
| 99 | 1 | my $token = qr/[!#\$&'*+.^_`|~0-9A-Za-z-]+/; | |||||||||
| 100 | |||||||||||
| 101 | |||||||||||
| 102 | # that's what RFC2616 says, which would frankly make for some wackass | ||||||||||
| 103 | # "tokens". | ||||||||||
| 104 | |||||||||||
| 105 | 0 | ▶ | subtype Token, as Str, where { /^$token$/o }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 106 | |||||||||||
| 107 | 1 | subtype MaybeToken, as Maybe[Token]; | |||||||||
| 108 | |||||||||||
| 109 | =head2 ContentType | ||||||||||
| 110 | |||||||||||
| 111 | A registered (or not) MIME type, in C<major/minor> notation. | ||||||||||
| 112 | |||||||||||
| 113 | =cut | ||||||||||
| 114 | |||||||||||
| 115 | 0 | ▶ | subtype ContentType, as Str, where { m!^$token/$token$!o }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 116 | |||||||||||
| 117 | 0 | ▶ | subtype RFC3066, as Str, where { m!^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$! }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 118 | |||||||||||
| 119 | =head2 NonNegativeInt | ||||||||||
| 120 | |||||||||||
| 121 | An integer which is zero or greater. Kinda like an unsigned int, I | ||||||||||
| 122 | suppose, except I don't care about how the underlying integer is | ||||||||||
| 123 | implemented, I just care that it's at least zero. | ||||||||||
| 124 | |||||||||||
| 125 | =cut | ||||||||||
| 126 | |||||||||||
| 127 | 0 | ▶ | subtype NonNegativeInt, as Int, where { $_ >= 0 }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 128 | |||||||||||
| 129 | =head2 StoreObject | ||||||||||
| 130 | |||||||||||
| 131 | =cut | ||||||||||
| 132 | |||||||||||
| 133 | 1 | subtype StoreObject, as class_type('Store::Digest::Object'); | |||||||||
| 134 | |||||||||||
| 135 | =head1 AUTHOR | ||||||||||
| 136 | |||||||||||
| 137 | Dorian Taylor, C<< <dorian at cpan.org> >> | ||||||||||
| 138 | |||||||||||
| 139 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 140 | |||||||||||
| 141 | Copyright 2012 Dorian Taylor. | ||||||||||
| 142 | |||||||||||
| 143 | Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| 144 | you may not use this file except in compliance with the License. | ||||||||||
| 145 | You may obtain a copy of the License at | ||||||||||
| 146 | |||||||||||
| 147 | L<http://www.apache.org/licenses/LICENSE-2.0> | ||||||||||
| 148 | |||||||||||
| 149 | Unless required by applicable law or agreed to in writing, software | ||||||||||
| 150 | distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| 151 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| 152 | See the License for the specific language governing permissions and | ||||||||||
| 153 | limitations under the License. | ||||||||||
| 154 | |||||||||||
| 155 | |||||||||||
| 156 | =cut | ||||||||||
| 157 | |||||||||||
| 158 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 159 | |||||||||||
| 160 | 1 | 1; # End of Store::Digest::Types | |||||||||