File Coverage

blib/lib/App/SmokeBrew/Types.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 32 32 100.0


line stmt bran cond sub pod time code
1             package App::SmokeBrew::Types;
2             $App::SmokeBrew::Types::VERSION = '1.00';
3             #ABSTRACT: Moose types for smokebrew
4              
5 5     5   498223 use strict;
  5         17  
  5         185  
6 5     5   27 use warnings;
  5         12  
  5         207  
7              
8             use MooseX::Types
9 5     5   1773 -declare => [qw(ArrayRefUri PerlVersion ArrayRefStr)];
  5         143183  
  5         59  
10              
11 5     5   27983 use Moose::Util::TypeConstraints;
  5         12  
  5         26  
12              
13 5     5   11923 use MooseX::Types::Moose qw[Str ArrayRef];
  5         52784  
  5         48  
14 5     5   27879 use MooseX::Types::URI qw[to_Uri Uri];
  5         1362257  
  5         39  
15              
16 5     5   12206 use Module::CoreList;
  5         114452  
  5         61  
17 5     5   1669 use Perl::Version;
  5         2966  
  5         1816  
18              
19             # Thanks to Florian Ragwitz for this magic
20              
21             subtype 'ArrayRefUri', as ArrayRef[Uri];
22              
23             coerce 'ArrayRefUri', from Str, via { [to_Uri($_)] };
24             coerce 'ArrayRefUri', from ArrayRef, via { [map { to_Uri($_) } @$_] };
25              
26             # This is my own magic
27              
28             subtype( 'PerlVersion', as 'Perl::Version',
29             where { ( my $ver = Perl::Version->new($_)->numify ) =~ s/_//g;
30             $ver >= 5.006 and
31             scalar grep { $ver eq sprintf('%.6f',$_) } keys %Module::CoreList::released },
32             message { "The version ($_) given is not a valid Perl version and is too old (< 5.006)" },
33             );
34              
35             coerce( 'PerlVersion', from 'Str', via { Perl::Version->new($_) } );
36              
37             subtype( 'ArrayRefStr', as ArrayRef[Str] );
38             coerce( 'ArrayRefStr', from 'Str', via { [ $_ ] } );
39              
40             qq[Smokin'];
41              
42             __END__
43              
44             =pod
45              
46             =encoding UTF-8
47              
48             =head1 NAME
49              
50             App::SmokeBrew::Types - Moose types for smokebrew
51              
52             =head1 VERSION
53              
54             version 1.00
55              
56             =head1 SYNOPSIS
57              
58             use App::SmokeBrew::Types qw[ArrayRefUri PerlVersion ArrayRefStr];
59              
60             has 'version' => (
61             is => 'ro',
62             isa => 'PerlVersion',
63             coerce => 1,
64             );
65              
66             has 'things' => (
67             is => 'ro',
68             isa => 'ArrayRefStr',
69             coerce => 1,
70             );
71              
72             has 'websites' => (
73             is => 'ro',
74             isa => 'ArrayRefUri',
75             coerce => 1,
76             );
77              
78             =head1 DESCRIPTION
79              
80             App::SmokeBrew::Types is a library of L<Moose> types for L<smokebrew>.
81              
82             =head1 TYPES
83              
84             It provides the following types:
85              
86             =over
87              
88             =item C<PerlVersion>
89              
90             A L<Perl::Version> object.
91              
92             Coerced from C<Str> via C<new> in L<Perl::Version>
93              
94             Constrained to existing in L<Module::CoreList> C<released> and being >= C<5.006>
95              
96             =item C<ArrayRefUri>
97              
98             An arrayref of L<URI> objects.
99              
100             Coerces from <Str> and C<ArrayRef[Str]> via L<MooseX::Types::URI>
101              
102             =item C<ArrayRefStr>
103              
104             An arrayref of C<Str>.
105              
106             Coerces from C<Str>.
107              
108             =back
109              
110             =head1 KUDOS
111              
112             Thanks to Florian Ragwitz for the L<MooseX::Types::URI> sugar.
113              
114             =head1 SEE ALSO
115              
116             L<URI>
117              
118             L<Perl::Version>
119              
120             L<MooseX::Types::URI>
121              
122             =head1 AUTHOR
123              
124             Chris Williams <chris@bingosnet.co.uk>
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             This software is copyright (c) 2020 by Chris Williams.
129              
130             This is free software; you can redistribute it and/or modify it under
131             the same terms as the Perl 5 programming language system itself.
132              
133             =cut