blib/lib/MMM/Sylk.pm

filter: Statementstmt 93.0% 67 / 72 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 5 totaltotal 86.2% 88 / 102 CC 9 SCAR 9.2
CC
9
Cov
90%
print
5.0
_print_sylk_line
3.0
push_record
2.2
CRAP 2.5
↑ Summary
1 package MMM::Sylk;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @ISA = qw(Exporter);
11  
12 # Items to export into callers namespace by default. Note: do not export
13 # names by default without a very good reason. Use EXPORT_OK instead.
14 # Do not simply export all your public functions/methods/constants.
15  
16 # This allows declaration use Sylk ':all';
17 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18 # will save memory.
19 1 our %EXPORT_TAGS = ( 'all' => [ qw(
20
21 ) ] );
22  
23 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
24  
25 1 our @EXPORT = qw(
26
27 );
28 1 our $VERSION = '0.02';
29  
30 1 our $EOL = "\n";
31  
32 # Preloaded methods go here.
33  
34  
35 sub new
36 1 ▶{
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
37 1 my @this;
38  
39 1 ▶ if( ref($_[1]) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[1] eq "HASH") 1 0 1
40 {
41 1 $this[1] = [ @{ $_[1]->{FirstRecord} } ];
42 }
43  
44 1 $this[0] = [];
45 1 return bless \@this;
46 }
47  
48 sub push_record
49 4 ▶{
Subroutine push_record: called CC=2 SCAR=7.9
Pod undocumented
50 4 my $this = shift;
51  
52 4 ▶ if( ref($_[0]) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 4 0 4
53 {
54 4 push @{ $this->[0] }, $_[0];
55 } else
56 {
57 0 push @{ $this->[0] }, [ @_ ];
58 }
59 }
60  
61 sub clear
62 0 ▶{
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
63 0 my $this = shift;
64 0 @{ $this->[0] } = ();
65 }
66  
67 2 ▶sub _SYLK_HEAD { "ID;PWXL;N;E" . $EOL }
Subroutine _SYLK_HEAD: called CC=1 SCAR=0.0
68 2 ▶sub _SYLK_TAIL { "E" }
Subroutine _SYLK_TAIL: called CC=1 SCAR=0.0
69  
70  
71 sub print
72 2 ▶{
Subroutine print: called CC=5 SCAR=16.1
Pod undocumented
73 2 my $this = shift;
74 2 my $output = shift;
75 2 my $headers = $this->[1];
76 2 my $line = 0;
77
78 2 ▶ if( ref($output) eq 'SCALAR' ) { $$output .= _SYLK_HEAD(); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $output eq 'SCALAR') { } 1 1 2
79 1 else { print $output _SYLK_HEAD(); }
80  
81 2 ▶ if( $headers )
Branch: 1 branch
BranchTrueFalseTotal
if ($headers) 2 0 2
82 {
83 2 $line = 1;
84 2 _print_sylk_line( $output, $line, $headers );
85 }
86 2 for my $r( @{ $this->[0] } )
87 {
88 8 ++$line;
89 8 _print_sylk_line( $output, $line, $r );
90 }
91 2 ▶ if( ref($output) eq 'SCALAR' ) { $$output .= _SYLK_TAIL(); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $output eq 'SCALAR') { } 1 1 2
92 1 else { print $output _SYLK_TAIL(); }
93 }
94  
95 sub as_string
96 1 ▶{
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
97 1 my $this = shift;
98 1 my $output;
99 1 $this->print(\$output);
100 1 return $output;
101 }
102  
103 1 my %encodings =
104 (
105 'à' => 'NAa',
106 'è' => 'NAe',
107 'é' => 'NBe',
108 'ò' => 'NAo',
109 'ç' => 'NKc',
110 'ì' => 'NAi',
111 '°' => 'N0'
112 );
113  
114 1 my $encodings_charlist = join "", keys %encodings;
115 sub _sylk_escape
116 30 ▶{
Subroutine _sylk_escape: called CC=1 SCAR=0.0
117 30 $_[0] =~ s/([$encodings_charlist])/chr(27) . $encodings{$1}/ge
118 }
119  
120 sub _print_sylk_line
121 10 ▶{
Subroutine _print_sylk_line: called CC=3 SCAR=11.0
122 10 my ($output, $line, $record ) = @_;
123  
124 # my $out = "C;Y$line;";
125 10 my $out;
126  
127 10 my $count = 1;
128 10 for my $f ( @$record )
129 {
130 30 _sylk_escape($f);
131 30 $out .= "C;Y$line;X$count;K\"$f\"$EOL";
132 30 ++$count;
133 }
134 10 ▶ if( ref($output) eq 'SCALAR' ) { $$output .= $out; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $output eq 'SCALAR') { } 5 5 10
135 5 else { print $output $out; }
136 }
137  
138  
139  
140  
141 # Autoload methods go after =cut, and are processed by the autosplit program.
142  
143 1 1;
144 __END__
↑ Summary