| 1 | package Data::Record::Serialize; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Flexible serialization of a record | ||||||||||
| 4 | |||||||||||
| 5 | 21 | ▶ | use 5.010000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 21 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 21 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 21 | ▶ | use warnings::register qw( Encode::dbi::queue ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 21 | ▶ | use Data::Record::Serialize::Error -all; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 21 | our $VERSION = '2.05'; | |||||||||
| 15 | |||||||||||
| 16 | use Package::Variant | ||||||||||
| 17 | 21 | ▶ | importing => [ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | subs => [qw( with has rewrite_encode rewrite_sink )]; | |||||||||
| 39 | |||||||||||
| 40 | 21 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | 95 | ▶ | sub make_variant { | ||||||||
|
Subroutine
make_variant: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 47 | 95 | my ( undef, $target, %attr ) = @_; | |||||||||
| 48 | |||||||||||
| 49 | error( 'attribute::value', 'must specify <encode> attribute' ) | ||||||||||
| 50 | 95 | ▶ | unless defined $attr{encode}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 94 | with 'Data::Record::Serialize::Role::Base'; | |||||||||
| 53 | |||||||||||
| 54 | 94 | my $encoder = rewrite_encode( $attr{encode} ); | |||||||||
| 55 | |||||||||||
| 56 | 94 | with $encoder; | |||||||||
| 57 | |||||||||||
| 58 | 94 | ▶ | if ( $target->does( 'Data::Record::Serialize::Role::Sink' ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | |||||||||||
| 60 | error( 'attribute::value', | ||||||||||
| 61 | "encoder ($encoder) is already a sink; don't specify a sink attribute\n" ) | ||||||||||
| 62 | 45 | ▶ | if defined $attr{sink}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | else { | ||||||||||
| 66 | 49 | ▶ | with rewrite_sink( $attr{sink} ? $attr{sink} : 'stream' ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 93 | 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 | 95 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 282 | 95 | my $class = shift; | |||||||||
| 283 | 95 | ▶ | my $attr = 'HASH' eq ref $_[0] ? shift : {@_}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 284 | |||||||||||
| 285 | my %class_attr = ( | ||||||||||
| 286 | encode => $attr->{encode}, | ||||||||||
| 287 | sink => $attr->{sink}, | ||||||||||
| 288 | 95 | ); | |||||||||
| 289 | |||||||||||
| 290 | 95 | $class = Package::Variant->build_variant_of( __PACKAGE__, %class_attr ); | |||||||||
| 291 | |||||||||||
| 292 | 93 | return $class->new( $attr ); | |||||||||
| 293 | } | ||||||||||
| 294 | |||||||||||
| 295 | 21 | 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__ | ||||||||||