Serializer/YAML.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 100% 41 / 41 CC 3 SCAR 3.1
CC
3
Cov
100%
get_freezer
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.4
« Serializer/JSON.pm ↑ Summary
1 package DBIx::Class::InflateColumn::Serializer::YAML;
2 {
3 3 $DBIx::Class::InflateColumn::Serializer::YAML::VERSION = '0.06';
4 }
5  
6 =head1 NAME
7  
8 DBIx::Class::InflateColumn::Serializer::YAML - YAML Inflator
9  
10 =head1 SYNOPSIS
11  
12 package MySchema::Table;
13 use base 'DBIx::Class';
14  
15 __PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
16 __PACKAGE__->add_columns(
17 'data_column' => {
18 'data_type' => 'VARCHAR',
19 'size' => 255,
20 'serializer_class' => 'YAML'
21 }
22 );
23  
24 Then in your code...
25  
26 my $struct = { 'I' => { 'am' => 'a struct' };
27 $obj->data_column($struct);
28 $obj->update;
29  
30 And you can recover your data structure with:
31  
32 my $obj = ...->find(...);
33 my $struct = $obj->data_column;
34  
35 The data structures you assign to "data_column" will be saved in the database in YAML format.
36  
37 =cut
38  
39 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 3 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 =over 4
45  
46 =item get_freezer
47  
48 Called by DBIx::Class::InflateColumn::Serializer to get the routine that serializes
49 the data passed to it. Returns a coderef.
50  
51 =cut
52  
53 sub get_freezer{
54 6 ▶ my ($class, $column, $info, $args) = @_;
Subroutine get_freezer: called CC=2 SCAR=6.9
Pod documented
55  
56 6 ▶ if (defined $info->{'size'}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{'size'}) { } 3 3 6
57 3 my $size = $info->{'size'};
58 return sub {
59 2 ▶ my $s = YAML::Dump(shift);
Subroutine __ANON__: called CC=2 SCAR=6.9
60 2 ▶ croak "serialization too big" if (length($s) > $size);
Branch: 1 branch
BranchTrueFalseTotal
if length $s > $size 1 1 2
61 1 return $s;
62 3 };
63 } else {
64 return sub {
65 2 ▶ return YAML::Dump(shift);
Subroutine __ANON__: called CC=1 SCAR=0.0
66 3 };
67 }
68 }
69  
70 =item get_unfreezer
71  
72 Called by DBIx::Class::InflateColumn::Serializer to get the routine that deserializes
73 the data stored in the column. Returns a coderef.
74  
75 =back
76  
77 =cut
78  
79 sub get_unfreezer {
80 return sub {
81 3 ▶ return YAML::Load(shift);
Subroutine __ANON__: called CC=1 SCAR=0.0
82 6 ▶ };
Subroutine get_unfreezer: called CC=1 SCAR=0.0
Pod documented
83 }
84  
85  
86 3 1;
« Serializer/JSON.pm ↑ Summary