File Coverage

blib/lib/Data/Record/Serialize.pm
Criterion Covered Total %
statement 34 34 100.0
branch 9 10 90.0
condition n/a
subroutine 9 9 100.0
pod 1 2 50.0
total 53 55 96.3


line stmt bran cond sub pod time code
1             package Data::Record::Serialize;
2              
3             # ABSTRACT: Flexible serialization of a record
4              
5 20     20   4441674 use 5.010000;
  20         83  
6              
7 20     20   137 use strict;
  20         59  
  20         752  
8 20     20   110 use warnings;
  20         40  
  20         1303  
9              
10 20     20   143 use warnings::register qw( Encode::dbi::queue );
  20         51  
  20         2111  
11              
12 20     20   14402 use Data::Record::Serialize::Error -all;
  20         70  
  20         201  
13              
14             our $VERSION = '2.02';
15              
16             use Package::Variant
17 20         421 importing => [
18             'Moo',
19             'String::RewritePrefix' => [
20             rewrite => {
21             -as => 'rewrite_encode',
22             prefixes => {
23             q{} => 'Data::Record::Serialize::Encode::',
24             q{+} => q{},
25             },
26             },
27             ],
28             'String::RewritePrefix' => [
29             rewrite => {
30             -as => 'rewrite_sink',
31             prefixes => {
32             q{} => 'Data::Record::Serialize::Sink::',
33             q{+} => q{},
34             },
35             },
36             ],
37             ],
38 20     20   16145 subs => [qw( with has rewrite_encode rewrite_sink )];
  20         196577  
39              
40 20     20   15723 use namespace::clean;
  20         354374  
  20         1497  
41              
42              
43              
44              
45              
46             sub make_variant {
47 69     69 0 700509 my ( undef, $target, %attr ) = @_;
48              
49             error( 'attribute::value', 'must specify attribute' )
50 69 100       462 unless defined $attr{encode};
51              
52 68         414 with 'Data::Record::Serialize::Role::Base';
53              
54 68         367252 my $encoder = rewrite_encode( $attr{encode} );
55              
56 68         3507 with $encoder;
57              
58 68 100       133680 if ( $target->does( 'Data::Record::Serialize::Role::Sink' ) ) {
59              
60             error( 'attribute::value',
61             "encoder ($encoder) is already a sink; don't specify a sink attribute\n" )
62 42 100       1369 if defined $attr{sink};
63             }
64              
65             else {
66 26 100       1289 with rewrite_sink( $attr{sink} ? $attr{sink} : 'stream' );
67             }
68              
69 67         42332 with 'Data::Record::Serialize::Role::Default';
70             }
71              
72              
73              
74              
75              
76              
77              
78              
79              
80              
81              
82              
83              
84              
85              
86              
87              
88              
89              
90              
91              
92              
93              
94              
95              
96              
97              
98              
99              
100              
101              
102              
103              
104              
105              
106              
107              
108              
109              
110              
111              
112              
113              
114              
115              
116              
117              
118              
119              
120              
121              
122              
123              
124              
125              
126              
127              
128              
129              
130              
131              
132              
133              
134              
135              
136              
137              
138              
139              
140              
141              
142              
143              
144              
145              
146              
147              
148              
149              
150              
151              
152              
153              
154              
155              
156              
157              
158              
159              
160              
161              
162              
163              
164              
165              
166              
167              
168              
169              
170              
171              
172              
173              
174              
175              
176              
177              
178              
179              
180              
181              
182              
183              
184              
185              
186              
187              
188              
189              
190              
191              
192              
193              
194              
195              
196              
197              
198              
199              
200              
201              
202              
203              
204              
205              
206              
207              
208              
209              
210              
211              
212              
213              
214              
215              
216              
217              
218              
219              
220              
221              
222              
223              
224              
225              
226              
227              
228              
229              
230              
231              
232              
233              
234              
235              
236              
237              
238              
239              
240              
241              
242              
243              
244              
245              
246              
247              
248              
249              
250              
251              
252              
253              
254              
255              
256              
257              
258              
259              
260              
261              
262              
263              
264              
265              
266              
267              
268              
269              
270              
271              
272              
273              
274              
275              
276              
277              
278              
279              
280              
281             sub new {
282 69     69 1 6279528 my $class = shift;
283 69 50       684 my $attr = 'HASH' eq ref $_[0] ? shift : {@_};
284              
285             my %class_attr = (
286             encode => $attr->{encode},
287             sink => $attr->{sink},
288 69         552 );
289              
290 69         779 $class = Package::Variant->build_variant_of( __PACKAGE__, %class_attr );
291              
292 67         228323 return $class->new( $attr );
293             }
294              
295             1;
296              
297              
298             #
299             # This file is part of Data-Record-Serialize
300             #
301             # This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
302             #
303             # This is free software, licensed under:
304             #
305             # The GNU General Public License, Version 3, June 2007
306             #
307              
308             __END__