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 21     21   3341359 use 5.010000;
  21         78  
6              
7 21     21   100 use strict;
  21         58  
  21         528  
8 21     21   81 use warnings;
  21         27  
  21         883  
9              
10 21     21   114 use warnings::register qw( Encode::dbi::queue );
  21         53  
  21         1578  
11              
12 21     21   8266 use Data::Record::Serialize::Error -all;
  21         57  
  21         156  
13              
14             our $VERSION = '2.03';
15              
16             use Package::Variant
17 21         337 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 21     21   12914 subs => [qw( with has rewrite_encode rewrite_sink )];
  21         143332  
39              
40 21     21   11683 use namespace::clean;
  21         262152  
  21         940  
41              
42              
43              
44              
45              
46             sub make_variant {
47 70     70 0 502301 my ( undef, $target, %attr ) = @_;
48              
49             error( 'attribute::value', 'must specify attribute' )
50 70 100       320 unless defined $attr{encode};
51              
52 69         291 with 'Data::Record::Serialize::Role::Base';
53              
54 69         261592 my $encoder = rewrite_encode( $attr{encode} );
55              
56 69         2585 with $encoder;
57              
58 69 100       94425 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       1008 if defined $attr{sink};
63             }
64              
65             else {
66 27 100       982 with rewrite_sink( $attr{sink} ? $attr{sink} : 'stream' );
67             }
68              
69 68         31208 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 70     70 1 4316478 my $class = shift;
283 70 50       535 my $attr = 'HASH' eq ref $_[0] ? shift : {@_};
284              
285             my %class_attr = (
286             encode => $attr->{encode},
287             sink => $attr->{sink},
288 70         401 );
289              
290 70         638 $class = Package::Variant->build_variant_of( __PACKAGE__, %class_attr );
291              
292 68         148526 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__