CAB/Datum.pm

filter: Statementstmt 53.1% 17 / 32 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 44.4% 4 / 9 Podpod 60.0% 3 / 5 totaltotal 28.5% 24 / 84 CC 14 SCAR 30.6
CC
14
Cov
27%
toToken
30.0
toSentence
30.0
toDocument
30.0
CRAP 21.3
« CAB/Server/HTTP/Handler.pm ↑ Summary CAB/Analyzer/Automaton/Gfsm/XL.pm »
1 ## -*- Mode: CPerl -*-
2 ##
3 ## File: DTA::CAB::Datum.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: generic API for data (tokens,sentences,documents,...) passed to/from DTA::CAB::Analyzer
6  
7 package DTA::CAB::Datum;
8 1 ▶use DTA::CAB::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 ##==============================================================================
14 ## Globals
15 ##==============================================================================
16  
17 1 our @ISA = qw(Exporter DTA::CAB::Logger);
18  
19 1 our @EXPORT = qw(toToken toSentence toDocument);
20 1 our @EXPORT_OK = @EXPORT;
21 1 our %EXPORT_TAGS = (all=>\@EXPORT_OK);
22  
23 ##==============================================================================
24 ## Constructors etc.
25 ##==============================================================================
26  
27 ## $dat = $CLASS_OR_OBJECT->new(%args)
28 ## + %$dat, %args:
29 ## _attrs => \%attrs, ##-- scalar attributes ($key=>$val,...), e.g. for xml pass-through
30 ## _dtrs => \@dtrs, ##-- structural daughters (DTA::CAB::Datum objects), e.g. for xml pass-through
31 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
32 0 ▶ return bless {@_[1..$#_]}, ref($_[0])||$_[0];
Condition0%0/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
33 }
34  
35 ##==============================================================================
36 ## Utilities
37 ##==============================================================================
38  
39 ## $tok = CLASS::toToken($tok)
40 ## $tok = CLASS::toToken($text)
41  
42 ## + creates a new token object or returns its argument
43 0 ▶sub toToken {
Subroutine toToken: not called CC=5 SCAR=34.0
Pod documented
44 # return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Token'));
45 # return bless({text=>$_[0]},'DTA::CAB::Token') if (!ref($_[0]));
46 # return bless($_[0],'DTA::CAB::Token') if (ref($_[0]) eq 'HASH' && exists($_[0]{text}));
47 # return DTA::CAB::Token->new(@_); ##-- default
48 ##--
49 0 ▶ return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Token'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "DTA::CAB::Token") 0 0 0
50 0 ▶ return {text=>$_[0]} if (!ref($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 0 0
51 0 ▶ return $_[0] if (ref($_[0]) eq 'HASH' && exists($_[0]{text}));
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" and exists $_[0]{"text"} 0 0 0
Condition0%0/3
ref $_[0] eq "HASH" and exists $_[0]{"text"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] eq "HASH" and exists $_[0]{"text"}
ref $_[0] eq "HASH" exists $_[0]{"text"}
Truth table0%0/3
A and B
A= ref $_[0] eq "HASH"B= exists $_[0]{"text"}
ABresult
0X0
100
111
52 0 return DTA::CAB::Token->new(@_); ##-- default
53 }
54  
55 ## $sent = CLASS::toSentence($sent)
56 ## $sent = CLASS::toSentence(\@tokens)
57 ## + creates a new sentence object or returns its argument
58 0 ▶sub toSentence {
Subroutine toSentence: not called CC=5 SCAR=34.0
Pod documented
59 # return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Sentence'));
60 # return bless({tokens=>$_[0]},'DTA::CAB::Sentence') if (UNIVERSAL::isa($_[0],'ARRAY'));
61 # return bless($_[0],'DTA::CAB::Sentence') if (ref($_[0]) eq 'HASH' && exists($_[0]{tokens}));
62 # return DTA::CAB::Sentence->new(@_); ##-- default
63 ##--
64 0 ▶ return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Sentence'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "DTA::CAB::Sentence") 0 0 0
65 0 ▶ return {tokens=>$_[0]} if (UNIVERSAL::isa($_[0],'ARRAY'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "ARRAY") 0 0 0
66 0 ▶ return $_[0] if (ref($_[0]) eq 'HASH' && exists($_[0]{tokens}));
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" and exists $_[0]{"tokens"} 0 0 0
Condition0%0/3
ref $_[0] eq "HASH" and exists $_[0]{"tokens"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] eq "HASH" and exists $_[0]{"tokens"}
ref $_[0] eq "HASH" exists $_[0]{"tokens"}
Truth table0%0/3
A and B
A= ref $_[0] eq "HASH"B= exists $_[0]{"tokens"}
ABresult
0X0
100
111
67 0 return DTA::CAB::Sentence->new(@_); ##-- default
68 }
69  
70 ## $doc = CLASS::toDocument($doc)
71 ## $doc = CLASS::toDocument(\@sents)
72 ## + creates a new document object or returns its argument
73 0 ▶sub toDocument {
Subroutine toDocument: not called CC=5 SCAR=34.0
Pod documented
74 0 ▶ return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Document'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "DTA::CAB::Document") 0 0 0
75 0 ▶ return bless({body=>$_[0]},'DTA::CAB::Document') if (UNIVERSAL::isa($_[0],'ARRAY'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "ARRAY") 0 0 0
76 0 ▶ return bless($_[0],'DTA::CAB::Document') if (ref($_[0]) eq 'HASH' && exists($_[0]{body}));
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" and exists $_[0]{"body"} 0 0 0
Condition0%0/3
ref $_[0] eq "HASH" and exists $_[0]{"body"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] eq "HASH" and exists $_[0]{"body"}
ref $_[0] eq "HASH" exists $_[0]{"body"}
Truth table0%0/3
A and B
A= ref $_[0] eq "HASH"B= exists $_[0]{"body"}
ABresult
0X0
100
111
77 0 return DTA::CAB::Document->new(@_); ##-- default
78 }
79  
80  
81 ## $thingy = $obj->TO_JSON()
82 ## + annoying wrapper for JSON::XS
83 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
84 0 return { %{$_[0]} };
85 }
86  
87 1 1; ##-- be happy
88  
89 __END__
« CAB/Server/HTTP/Handler.pm ↑ Summary CAB/Analyzer/Automaton/Gfsm/XL.pm »