File Coverage

blib/lib/Data/Record/Serialize/Util.pm
Criterion Covered Total %
statement 30 30 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 0 2 0.0
total 39 41 95.1


line stmt bran cond sub pod time code
1              
2             # ABSTRACT: Useful things
3              
4             use strict;
5 18     18   119 use warnings;
  18         36  
  18         475  
6 18     18   86 our $VERSION = '1.03'; # TRIAL
  18         37  
  18         778  
7              
8             use parent 'Exporter::Tiny';
9 18     18   100  
  18         30  
  18         109  
10             my @TYPE_CATEGORY_NAMES;
11             my %TYPES;
12             BEGIN {
13             @TYPE_CATEGORY_NAMES = qw(
14 18     18   1714 ANY
15             INTEGER
16             FLOAT
17             NUMBER
18             STRING
19             NOT_STRING
20             BOOLEAN
21             );
22              
23             %TYPES = (
24 18         493 T_INTEGER => 'I',
25             T_NUMBER => 'N',
26             T_STRING => 'S',
27             T_BOOLEAN => 'B',
28             );
29             }
30              
31             use enum @TYPE_CATEGORY_NAMES;
32 18     18   7227 use constant \%TYPES;
  18         18143  
  18         156  
33 18     18   8757  
  18         37  
  18         1732  
34             our @TYPE_CATEGORIES = map {; # add a ; to help 5.10
35             no strict 'refs'; ## no critic(ProhibitNoStrict)
36 18     18   98 $_->();
  18         36  
  18         6303  
37             } @TYPE_CATEGORY_NAMES;
38              
39             our %EXPORT_TAGS = (
40             types => [ keys %TYPES ],
41             categories => \@TYPE_CATEGORY_NAMES,
42             subs => [ qw( is_type index_types ) ],
43             );
44              
45             our @EXPORT_OK = map { @{$_} } values %EXPORT_TAGS;
46              
47             my @TypeRE;
48             $TypeRE[ $_->[0] ] = $_->[1]
49             for
50             [ ANY ,=> qr/.*/ ],
51             [ STRING ,=> qr/^S/i ],
52             [ FLOAT ,=> qr/^N/i ],
53             [ INTEGER ,=> qr/^I/i ],
54             [ BOOLEAN ,=> qr/^B/i ],
55             [ NUMBER ,=> qr/^[NI]/i ],
56             [ NOT_STRING ,=> qr/^[^S]+/ ];
57              
58             my ( $type, $type_enum ) = @_;
59             $type =~ $TypeRE[$type_enum];
60 111     111 0 195 }
61 111         640  
62             my ( $types ) = @_;
63              
64             my @fields = keys %$types;
65 61     61 0 127 my @type_index;
66              
67 61         220 for my $category ( @TYPE_CATEGORIES ) {
68 61         107 my $re = $TypeRE[$category];
69             $type_index[$category] = [ grep { $types->{$_} =~ $re } @fields ];
70 61         151 }
71 427         1014  
72 427         582 return \@type_index;
  1050         3399  
73             }
74              
75 61         388 1;
76              
77             #
78             # This file is part of Data-Record-Serialize
79             #
80             # This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
81             #
82             # This is free software, licensed under:
83             #
84             # The GNU General Public License, Version 3, June 2007
85             #
86              
87              
88             =pod
89              
90             =for :stopwords Diab Jerius Smithsonian Astrophysical Observatory
91              
92             =head1 NAME
93              
94             Data::Record::Serialize::Util - Useful things
95              
96             =head1 VERSION
97              
98             version 1.03
99              
100             =for Pod::Coverage index_types
101             is_type
102              
103             =head1 SUPPORT
104              
105             =head2 Bugs
106              
107             Please report any bugs or feature requests to bug-data-record-serialize@rt.cpan.org or through the web interface at: https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Record-Serialize
108              
109             =head2 Source
110              
111             Source is available at
112              
113             https://gitlab.com/djerius/data-record-serialize
114              
115             and may be cloned from
116              
117             https://gitlab.com/djerius/data-record-serialize.git
118              
119             =head1 SEE ALSO
120              
121             Please see those modules/websites for more information related to this module.
122              
123             =over 4
124              
125             =item *
126              
127             L<Data::Record::Serialize|Data::Record::Serialize>
128              
129             =back
130              
131             =head1 AUTHOR
132              
133             Diab Jerius <djerius@cpan.org>
134              
135             =head1 COPYRIGHT AND LICENSE
136              
137             This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
138              
139             This is free software, licensed under:
140              
141             The GNU General Public License, Version 3, June 2007
142              
143             =cut