KiokuDB/Backend/Serialize/YAML.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 100% 65 / 65 CC 5 SCAR 9.3
CC
5
Cov
100%
deserialize_from_stream
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
« KiokuDB/Test/Fixture/Sets.pm ↑ Summary KiokuDB/Set/Loaded.pm »
1 #!/usr/bin/perl
2  
3 package KiokuDB::Backend::Serialize::YAML;
4 5 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use YAML::XS qw(Load Dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 with qw(
13 KiokuDB::Backend::Serialize
14 KiokuDB::Backend::Role::UnicodeSafe
15 KiokuDB::Backend::TypeMap::Default::Storable
16 );
17  
18 sub serialize {
19 514 ▶ my ( $self, $entry ) = @_;
Subroutine serialize: called CC=1 SCAR=0.0
Pod documented
20  
21 514 my $clone = $entry->clone;
22  
23 514 $clone->clear_prev;
24 514 $clone->root( $entry->root );
25  
26 514 Dump($clone);
27 }
28  
29 sub deserialize {
30 607 ▶ my ( $self, $blob ) = @_;
Subroutine deserialize: called CC=1 SCAR=0.0
Pod documented
31  
32 607 return Load($blob);
33 }
34  
35 sub serialize_to_stream {
36 3 ▶ my ( $self, $fh, $entry ) = @_;
Subroutine serialize_to_stream: called CC=1 SCAR=0.0
Pod documented
37 3 $fh->print( $self->serialize($entry) );
38 }
39  
40 has _deserialize_buffer => (
41 isa => "ScalarRef",
42 is => "ro",
43 12 ▶ default => sub { my $x = ''; \$x },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 5 );
45  
46 sub deserialize_from_stream {
47 4 ▶ my ( $self, $fh ) = @_;
Subroutine deserialize_from_stream: called CC=5 SCAR=16.1
Pod documented
48  
49 4 local $_;
50 4 local $/ = "\n";
51  
52 4 my $buf = $self->_deserialize_buffer;
53  
54 4 ▶ while ( <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 15 2 17
55 15 ▶ if ( /^---/ and length($$buf) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^---/ and length $$buf) { } 2 13 15
Condition100%3/3
/^---/ and length $$buf
!ll&&!rl&&r
1212
MC/DC100%2/2
/^---/ and length $$buf
/^---/ length $$buf
Truth table100%3/3
A and B
A= /^---/B= length $$buf
ABresult
0X0
100
111
56 2 my @data = $self->deserialize($$buf);
57 2 $$buf = $_;
58 2 return @data;
59 } else {
60 13 $$buf .= $_;
61 }
62 }
63  
64 2 ▶ if ( length $$buf ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$buf) { } 1 1 2
65 1 my @data = $self->deserialize($$buf);
66 1 $$buf = '';
67 1 return @data;
68 } else {
69 1 return;
70 }
71 }
72  
73 5 __PACKAGE__
74  
75 __END__
76  
77 =pod
78  
79 =head1 NAME
80  
81 KiokuDB::Backend::Serialize::YAML - L<YAML::XS> based serialization of
82 L<KiokuDB::Entry> objects.
83  
84 =head1 SYNOPSIS
85  
86 package MyBackend;
87 use Moose;
88  
89 with qw(KiokuDB::Backend::Serialize::YAML);
90  
91 =head1 DESCRIPTION
92  
93 L<KiokuDB::Backend::Serialize::Delegate> is preferred to using this directly.
94  
95 =head1 METHODS
96  
97 =over 4
98  
99 =item serialize $entry
100  
101 Calls L<YAML::XS::Dump>
102  
103 =item deserialize $str
104  
105 Calls L<YAML::XS::Load>
106  
107 =item serialize_to_stream $fh, $entry
108  
109 Serializes the entry and prints to the file handle.
110  
111 =item deserialize_from_stream $fh
112  
113 Reads until a YAML document boundry is reached, and then deserializes the
114 current buffer.
115  
116 =back
« KiokuDB/Test/Fixture/Sets.pm ↑ Summary KiokuDB/Set/Loaded.pm »