DiaColloDB/Document/Storable.pm

filter: Statementstmt 47.8% 11 / 23 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 66.6% 2 / 3 totaltotal 40.0% 16 / 40 CC 5 SCAR 27.5
CC
5
Cov
35%
fromFile
30.0
new
2.0
extension
2.0
CRAP 15.7
« DiaColloDB/threads/shared.pm ↑ Summary DiaColloDB/EnumFile/Tied.pm »
1 ## -*- Mode: CPerl -*-
2 ## File: DiaColloDB::Document::Storable.pm
3 ## Author: Bryan Jurish <moocow@cpan.org>
4 ## Description: collocation db, source document, Storable (nstore_fd)
5  
6 package DiaColloDB::Document::Storable;
7 1 ▶use DiaColloDB::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 ##==============================================================================
12 ## Globals & Constants
13  
14 1 our @ISA = qw(DiaColloDB::Document);
15  
16 ##==============================================================================
17 ## Constructors etc.
18  
19 ## $doc = CLASS_OR_OBJECT->new(%args)
20 ## + %args, object structure:
21 ## (
22 ## ##-- document data
23 ## date =>$date, ##-- year
24 ## tokens =>\@tokens, ##-- tokens, including undef for EOS
25 ## meta =>\%meta, ##-- document metadata (e.g. author, title, collection, ...)
26 ## )
27 ## + each token in @tokens is a HASH-ref {w=>$word,p=>$pos,l=>$lemma,...}
28 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
29 0 my $that = shift;
30 0 my $doc = $that->SUPER::new(
31 @_, ##-- user arguments
32 );
33 0 return $doc;
34 }
35  
36 ##==============================================================================
37 ## API: I/O
38  
39  
40 ## $ext = $doc->extension()
41 ## + default extension, for Corpus::Compiled
42 0 ▶sub extension {
Subroutine extension: not called CC=1 SCAR=6.9
Pod undocumented
43 0 return '.sto';
44 }
45  
46 ##--------------------------------------------------------------
47 ## API: I/O: parse
48  
49 ## $bool = $doc->fromFile($filename_or_fh, %opts)
50 ## + parse tokens from $filename_or_fh
51 ## + %opts : clobbers %$doc
52 0 ▶sub fromFile {
Subroutine fromFile: not called CC=5 SCAR=34.0
Pod documented
53 0 my ($doc,$file,%opts) = @_;
54 0 ▶ $doc = $doc->new() if (!ref($doc));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $doc 0 0 0
55 0 @$doc{keys %opts} = values %opts;
56 0 ▶ $doc->{label} = ref($file) ? "$file" : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
57 0 ▶ my $ref = (ref($file)
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
58 ? Storable::fd_retrieve($file)
59 : Storable::retrieve($file));
60 0 ▶ $doc->logconfess("fromFile(): failed to load Storable object from '$file'")
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($ref, "HASH") 0 0 0
61 if (!UNIVERSAL::isa($ref,'HASH'));
62 0 @$doc{keys %$ref} = values %$ref;
63 0 return $doc;
64 }
65  
66 ##==============================================================================
67 ## Footer
68 1 1;
69  
70 __END__
« DiaColloDB/threads/shared.pm ↑ Summary DiaColloDB/EnumFile/Tied.pm »