CAB/Format/Storable.pm

filter: Statementstmt 67.3% 33 / 49 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 55.5% 10 / 18 Podpod 75.0% 6 / 8 totaltotal 54.4% 49 / 90 CC 8 SCAR 17.0
CC
8
Cov
53%
putRef
20.0
new
6.0
fromFh
6.0
CRAP 5.5
« CAB/Analyzer/Cache/Static/CDB.pm ↑ Summary CAB/Format/JSON.pm »
1 ## -*- Mode: CPerl -*-
2 ##
3 ## File: DTA::CAB::Format::Storable.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: Datum parser using Storable::freeze() & co.
6  
7 package DTA::CAB::Format::Storable;
8 1 ▶use DTA::CAB::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DTA::CAB::Datum ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use DTA::CAB::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use DTA::CAB::Sentence;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use DTA::CAB::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 ##==============================================================================
18 ## Globals
19 ##==============================================================================
20  
21 1 our @ISA = qw(DTA::CAB::Format);
22  
23 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
24 1 DTA::CAB::Format->registerFormat(name=>__PACKAGE__, filenameRegex=>qr/\.(?i:sto|bin)$/);
25 1 DTA::CAB::Format->registerFormat(name=>__PACKAGE__, short=>$_) foreach (qw(sto bin));
26 }
27  
28 ##==============================================================================
29 ## Constructors etc.
30 ##==============================================================================
31  
32 ## $fmt = CLASS_OR_OBJ->new(%args)
33 ## + object structure: assumed HASH
34 ## (
35 ## ##---- Input
36 ## doc => $doc, ##-- buffered input document
37 ## raw => $bool, ##-- uses forceDocument() if false (default)
38 ##
39 ## ##---- Output
40 ## #docbuf => $obj, ##-- an output object buffer (DTA::CAB::Document object)
41 ## netorder => $bool, ##-- if true (default), then store in network order
42 ##
43 ## ##---- INHERITED from DTA::CAB::Format
44 ## #utf8 => $bool, ##-- n/a
45 ## #level => $formatLevel, ##-- sets output level: n/a
46 ## #outbuf => $stringBuffer, ##-- buffered output
47 ## )
48 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
49 0 my $that = shift;
50 0 ▶ my $fmt = bless({
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
51 ##-- input
52 #doc => undef,
53  
54 ##-- output
55 #docbuf => DTA::CAB::Document->new(),
56 netorder => 1,
57  
58 ##-- i/o common
59 utf8 => undef, ##-- not applicable
60  
61 ##-- user args
62 @_
63 }, ref($that)||$that);
64 0 return $fmt;
65 }
66  
67 ##==============================================================================
68 ## Methods: Persistence
69 ##==============================================================================
70  
71 ## @keys = $class_or_obj->noSaveKeys()
72 ## + returns list of keys not to be saved
73 0 ▶sub noSaveKeys {
Subroutine noSaveKeys: not called CC=1 SCAR=6.9
Pod documented
74 0 return qw(doc); #docbuf
75 }
76  
77 ##=============================================================================
78 ## Methods: I/O: Generic
79 ##==============================================================================
80  
81 ## $fmt = $fmt->close()
82 ## + deletes $fmt->{doc} if present
83  
84 ## @layers = $fmt->iolayers
85 0 ▶sub iolayers {
Subroutine iolayers: not called CC=1 SCAR=6.9
Pod undocumented
86 0 return (':raw');
87 }
88  
89 ##=============================================================================
90 ## Methods: Input
91 ##==============================================================================
92  
93 ##--------------------------------------------------------------
94 ## Methods: Input: Input selection
95  
96 ## $fmt = $fmt->fromFh($fh)
97 0 ▶sub fromFh {
Subroutine fromFh: not called CC=2 SCAR=17.9
Pod documented
98 0 my ($fmt,$fh) = @_;
99 0 $fmt->DTA::CAB::Format::fromFh($fh);
100 0 ▶ $fmt->{doc} = Storable::retrieve_fd($fh)
Branch: 1 branch
BranchTrueFalseTotal
$fmt->{"doc"} = Storable::retrieve_fd($fh) or $fmt->logconfess("fromFh(): Storable::retrieve_fd() failed: $!") 0 0 0
101 or $fmt->logconfess("fromFh(): Storable::retrieve_fd() failed: $!");
102 0 return $fmt;
103 }
104  
105 ##--------------------------------------------------------------
106 ## Methods: Input: Generic API
107  
108 ## $doc = $fmt->parseDocument()
109 ## + just returns buffered object in $fmt->{doc}
110 0 ▶sub parseDocument {
Subroutine parseDocument: not called CC=2 SCAR=17.9
Pod documented
111 0 ▶ return $_[0]{raw} ? $_[0]{doc} : $_[0]->forceDocument( $_[0]{doc} );
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'raw'} ? : 0 0 0
112 }
113  
114  
115 ##==============================================================================
116 ## Methods: Output
117 ##==============================================================================
118  
119 ##--------------------------------------------------------------
120 ## Methods: Output: Generic
121  
122 ## $type = $fmt->mimeType()
123 ## + default returns text/plain
124 0 ▶sub mimeType { return 'application/octet-stream'; }
Subroutine mimeType: not called CC=1 SCAR=6.9
Pod documented
125  
126 ## $ext = $fmt->defaultExtension()
127 ## + returns default filename extension for this format
128 0 ▶sub defaultExtension { return '.bin'; }
Subroutine defaultExtension: not called CC=1 SCAR=6.9
Pod documented
129  
130  
131 ##--------------------------------------------------------------
132 ## Methods: Output: output selection
133 ## + inherited
134  
135 ##--------------------------------------------------------------
136 ## Methods: Output: Recommended API
137  
138 ## $fmt = $fmt->putRef($ref)
139 ## + wrapper for Storable::nstore_fd() rsp store_fd()
140 0 ▶sub putRef {
Subroutine putRef: not called CC=4 SCAR=30.0
Pod undocumented
141 0 ▶ if ($_[0]{netorder}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{'netorder'}) { } 0 0 0
142 Storable::nstore_fd($_[1],$_[0]{fh})
143 0 ▶ or $_[0]->logconfess("Storable::nstore_fd() failed for $_[1]: $!");
Branch: 1 branch
BranchTrueFalseTotal
Storable::nstore_fd($_[1], $_[0]{"fh"}) or $_[0]->logconfess("Storable::nstore_fd() failed for $_[1]: $!") 0 0 0
144 } else {
145 Storable::store_fd($_[1],$_[0]{fh})
146 0 ▶ or $_[0]->logconfess("Storable::store_fd() failed for $_[1]: $!");
Branch: 1 branch
BranchTrueFalseTotal
Storable::store_fd($_[1], $_[0]{"fh"}) or $_[0]->logconfess("Storable::store_fd() failed for $_[1]: $!") 0 0 0
147 }
148 0 return $_[0];
149 }
150  
151  
152 ## $fmt = $fmt->putToken($tok)
153 ## $fmt = $fmt->putSentence($sent)
154 ## $fmt = $fmt->putDocument($doc)
155 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
156 1 *putToken = \&putRef;
157 1 *putSentence = \&putRef;
158 1 *putDocument = \&putRef;
159 1 *putData = \&putRef;
160 }
161  
162 ##==============================================================================
163 ## Package Aliases
164 ##==============================================================================
165 package DTA::CAB::Format::Freeze;
166 1 our @ISA = qw(DTA::CAB::Format::Storable);
167  
168 1 1; ##-- be happy
169  
170 __END__
« CAB/Analyzer/Cache/Static/CDB.pm ↑ Summary CAB/Format/JSON.pm »