File Coverage

blib/lib/DiaColloDB/Document/Storable.pm
Criterion Covered Total %
statement 9 21 42.8
branch 0 8 0.0
condition n/a
subroutine 3 6 50.0
pod 2 3 66.6
total 14 38 36.8


line stmt bran cond sub pod time code
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     1   7 use DiaColloDB::Document;
  1         2  
  1         24  
8 1     1   5 use Storable;
  1         2  
  1         18  
9 1     1   107 use strict;
  1         2  
  1         215  
10              
11             ##==============================================================================
12             ## Globals & Constants
13              
14             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             sub new {
29 0     0 1   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             sub extension {
43 0     0 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             sub fromFile {
53 0     0 1   my ($doc,$file,%opts) = @_;
54 0 0         $doc = $doc->new() if (!ref($doc));
55 0           @$doc{keys %opts} = values %opts;
56 0 0         $doc->{label} = ref($file) ? "$file" : $file;
57 0 0         my $ref = (ref($file)
58             ? Storable::fd_retrieve($file)
59             : Storable::retrieve($file));
60 0 0         $doc->logconfess("fromFile(): failed to load Storable object from '$file'")
61             if (!UNIVERSAL::isa($ref,'HASH'));
62 0           @$doc{keys %$ref} = values %$ref;
63 0           return $doc;
64             }
65              
66             ##==============================================================================
67             ## Footer
68             1;
69              
70             __END__
71              
72              
73              
74