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