File Coverage

blib/lib/HTML/FormHandler/TraitFor/Types.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package HTML::FormHandler::TraitFor::Types;
2             # ABSTRACT: types used internally in FormHandler
3             $HTML::FormHandler::TraitFor::Types::VERSION = '0.40067';
4 143     143   71566 use Moose::Role;
  143         190  
  143         834  
5 143     143   474593 use Moose::Util::TypeConstraints;
  143         203  
  143         1102  
6              
7             subtype 'HFH::ArrayRefStr'
8             => as 'ArrayRef[Str]';
9              
10             coerce 'HFH::ArrayRefStr'
11             => from 'Str'
12             => via {
13             if( length $_ ) { return [$_] };
14             return [];
15             };
16              
17             coerce 'HFH::ArrayRefStr'
18             => from 'Undef'
19             => via { return []; };
20              
21             subtype 'HFH::SelectOptions'
22             => as 'ArrayRef[HashRef]';
23              
24             coerce 'HFH::SelectOptions'
25             => from 'ArrayRef[Str]'
26             => via {
27             my @options = @$_;
28             die "Options array must contain an even number of elements"
29             if @options % 2;
30             my $opts;
31             push @{$opts}, { value => shift @options, label => shift @options } while @options;
32             return $opts;
33             };
34              
35             coerce 'HFH::SelectOptions'
36             => from 'ArrayRef[ArrayRef]'
37             => via {
38             my @options = @{ $_[0][0] };
39             my $opts;
40             push @{$opts}, { value => $_, label => $_ } foreach @options;
41             return $opts;
42             };
43              
44 143     143   202501 no Moose::Util::TypeConstraints;
  143         216  
  143         644  
45             1;
46              
47             __END__
48              
49             =pod
50              
51             =encoding UTF-8
52              
53             =head1 NAME
54              
55             HTML::FormHandler::TraitFor::Types - types used internally in FormHandler
56              
57             =head1 VERSION
58              
59             version 0.40067
60              
61             =head1 AUTHOR
62              
63             FormHandler Contributors - see HTML::FormHandler
64              
65             =head1 COPYRIGHT AND LICENSE
66              
67             This software is copyright (c) 2016 by Gerda Shank.
68              
69             This is free software; you can redistribute it and/or modify it under
70             the same terms as the Perl 5 programming language system itself.
71              
72             =cut