CAB/Format/CSV.pm

filter: Statementstmt 75.7% 25 / 33 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 9 / 12 Podpod 66.6% 2 / 3 totaltotal 52.1% 36 / 69 CC 9 SCAR 37.2
CC
9
Cov
50%
token2buf
90.0
defaultExtension
2.0
parseCsvString
1.1
CRAP 41.1
« CAB/Server/XmlRpc.pm ↑ Summary CAB/Format/Raw/Base.pm »
1 ## -*- Mode: CPerl -*-
2 ##
3 ## File: DTA::CAB::Format::CSV.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: Datum parser: concise minimal-output human-readable text
6  
7 package DTA::CAB::Format::CSV;
8 1 ▶use DTA::CAB::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DTA::CAB::Format::TT;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use DTA::CAB::Datum ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 ##==============================================================================
16 ## Globals
17 ##==============================================================================
18  
19 1 our @ISA = qw(DTA::CAB::Format::TT);
20  
21 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 DTA::CAB::Format->registerFormat(name=>__PACKAGE__, filenameRegex=>qr/\.(?i:csv|cab\-csv)$/);
23 }
24  
25 ##==============================================================================
26 ## Constructors etc.
27 ##==============================================================================
28  
29 ## $fmt = CLASS_OR_OBJ->new(%args)
30 ## + object structure: assumed HASH
31 ## (
32 ## ##---- Input
33 ## doc => $doc, ##-- buffered input document
34 ##
35 ## ##---- Output
36 ## level => $formatLevel, ##-- output formatting level:
37 ## ## 0: text, xlit, canon, tag, lemma
38 ## ## 1: text, xlit, canon, tag, lemma, details
39 ## #outbuf => $stringBuffer, ##-- buffered output
40 ##
41 ## ##---- Common
42 ## utf8 => $bool, ##-- default: 1
43 ## )
44 ## + inherited from DTA::CAB::Format::TT
45  
46 ##==============================================================================
47 ## Methods: Persistence
48 ##==============================================================================
49  
50 ##==============================================================================
51 ## Methods: Input
52 ##==============================================================================
53  
54 ##--------------------------------------------------------------
55 ## Methods: Input: Local
56  
57 ## $fmt = $fmt->parseTextString(\$string)
58 1 ▶BEGIN { *parseTTString = \&parseCsvString; }
Subroutine BEGIN: called CC=1 SCAR=0.0
59 0 ▶sub parseCsvString {
Subroutine parseCsvString: not called CC=1 SCAR=1.2
Pod documented
60 0 my ($fmt,$src) = @_;
61 1 ▶ no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
62 0 $$src =~ s|^([^\t]+)(?:\t([^\t]*))?\t([^\t]*)\t([^\t]*)\t([^\t\r\n]*)(?:\t([^\t\r\n]*))?$|$1\t[xlit] $2\t[dmoot/tag] $3\t[moot/word] $3\t[moot/tag] $4\t[moot/lemma] $5\t[moot/details] $6|mg;
63 0 return DTA::CAB::Format::TT::parseTTString($fmt,$src);
64 }
65  
66 ##==============================================================================
67 ## Methods: Output
68 ##==============================================================================
69  
70 ##--------------------------------------------------------------
71 ## Methods: Output: Generic
72  
73 ## $ext = $fmt->defaultExtension()
74 ## + returns default filename extension for this format
75 0 ▶sub defaultExtension { return '.csv'; }
Subroutine defaultExtension: not called CC=1 SCAR=6.9
Pod documented
76  
77 ##--------------------------------------------------------------
78 ## Methods: Output: output selection
79  
80 ## \$buf = $fmt->token2buf($tok,\$buf)
81 ## + buffer output for a single token
82 ## + override implements CSV format
83 0 ▶sub token2buf {
Subroutine token2buf: not called CC=9 SCAR=45.0
Pod undocumented
84 0 ▶ my $bufr = ($_[2] ? $_[2] : \(my $buf=''));
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 0 0
85 $$bufr = join("\t",
86 $_[1]{text},
87 ($_[1]{xlit} ? $_[1]{xlit}{latin1Text} : ''),
88 0 ▶ ($_[1]{moot} ? (@{$_[1]{moot}}{qw(word tag lemma)}) : ('','','')),
Branch: 2 branches
BranchTrueFalseTotal
($_[0]{'level'} // 0) >= 1 ? : 0 0 0
$_[1]{'moot'} && $_[1]{'moot'}{'details'} ? : 0 0 0
Condition0%0/7
$_[0]{"level"} // 0
l!l
00
$_[1]{"moot"} and $_[1]{"moot"}{"details"}
!ll&&!rl&&r
000
$_[1]{"moot"}{"details"}{"details"} // "*"
l!l
00
MC/DC0%0/1
$_[0]{"level"} // 0
$_[0]{"level"}
MC/DC0%0/2
$_[1]{"moot"} and $_[1]{"moot"}{"details"}
$_[1]{"moot"} $_[1]{"moot"}{"details"}
MC/DC0%0/1
$_[1]{"moot"}{"details"}{"details"} // "*"
$_[1]{"moot"}{"details"}{"details"}
Truth table0%0/2
A
A= $_[0]{"level"}
Aresult
11
00
Truth table0%0/3
A and B
A= $_[1]{"moot"}B= $_[1]{"moot"}{"details"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $_[1]{"moot"}{"details"}{"details"}
Aresult
11
00
89 (($_[0]{level}//0) >= 1
90 0 ▶ ? ($_[1]{moot} && $_[1]{moot}{details} ? ($_[1]{moot}{details}{details}//'*') : '')
Branch: 2 branches
BranchTrueFalseTotal
$_[1]{'xlit'} ? : 0 0 0
$_[1]{'moot'} ? : 0 0 0
91 : qw())
92 )."\n";
93 0 return $bufr;
94 }
95  
96 1 1; ##-- be happy
97  
98 __END__
« CAB/Server/XmlRpc.pm ↑ Summary CAB/Format/Raw/Base.pm »