lpOD/Common.pm

filter: Statementstmt 31.1% 122 / 392 Branchbran 0.0% 0 / 186 Conditioncond 0.0% 0 / 88 MC/DCmcdc 0.0% 0 / 50 Subroutinesub 33.3% 20 / 60 Podpod 28.2% 11 / 39 totaltotal 18.7% 153 / 815 CC 133 SCAR 41.1
CC
133
Cov
18%
search_string
210.0
check_odf_value
132.0
input_2d_value
132.0
CRAP 60.8
↑ Summary lpOD/Table.pm »
1 #=============================================================================
2 #
3 # Copyright (c) 2010 Ars Aperta, Itaapy, Pierlis, Talend.
4 # Copyright (c) 2014 Jean-Marie Gouarné.
5 # Author: Jean-Marie Gouarné <jean.marie.gouarne@online.fr>
6 #
7 #=============================================================================
8 2 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use feature qw/current_sub/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 #=============================================================================
12 # Common lpOD/Perl parameters and utility functions
13 #=============================================================================
14 package ODF::lpOD::Common;
15 2 our $VERSION = '1.013';
16 2 ▶use constant PACKAGE_DATE => '2014-04-30T08:32:52';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 #-----------------------------------------------------------------------------
18 2 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use match::simple qw(match);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Carp qw/carp confess cluck/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 our @EXPORT = qw
25 (
26 lpod_common lpod
27  
28 odf_get_document odf_new_document odf_create_document
29 odf_new_document_from_template odf_new_document_from_type
30  
31 odf_get_container odf_new_container
32 odf_new_container_from_template odf_new_container_from_type
33  
34 odf_get_xmlpart
35  
36 odf_create_element odf_create_paragraph odf_create_heading
37 odf_create_section odf_create_draw_page
38 odf_create_shape
39 odf_create_area odf_create_rectangle odf_create_ellipse
40 odf_create_vector odf_create_line odf_create_connector
41 odf_create_frame odf_create_text_frame odf_create_image_frame
42 odf_create_image
43 odf_create_list
44 odf_create_table odf_create_column odf_create_row odf_create_cell
45 odf_create_column_group odf_create_row_group
46 odf_create_field odf_create_simple_variable odf_create_user_variable
47 odf_create_note odf_create_annotation
48 odf_create_style odf_create_font_declaration
49 odf_create_toc
50  
51 odf_document odf_container
52 odf_xmlpart odf_content odf_styles odf_meta odf_settings odf_manifest
53  
54 odf_element odf_text_node
55 odf_text_element odf_text_hyperlink
56 odf_bibliography_mark odf_note odf_annotation odf_changed_region
57 odf_paragraph odf_heading odf_draw_page odf_image odf_shape odf_frame
58 odf_area odf_rectangle odf_ellipse odf_vector odf_line odf_connector
59 odf_field odf_variable odf_simple_variable odf_user_variable
60 odf_text_field odf_classify_text_field
61 odf_list odf_table odf_column odf_row odf_cell
62 odf_matrix odf_column_group odf_row_group odf_table_element
63 odf_structured_container
64 odf_section odf_toc odf_named_range
65 odf_file_entry
66  
67 odf_style
68 odf_text_style odf_paragraph_style
69 odf_list_style odf_list_level_style odf_outline_style
70 odf_table_style odf_column_style odf_row_style odf_cell_style
71 odf_data_style
72 odf_master_page odf_page_end_style odf_drawing_page_style
73 odf_page_layout odf_presentation_page_layout
74 odf_graphic_style odf_gradient
75 odf_font_declaration
76  
77 TRUE FALSE PRETTY
78 is_true is_false defined_false
79 is_odf_datatype odf_boolean process_options
80 alpha_to_num translate_coordinates translate_range
81  
82 xelt xtwig
83  
84 META CONTENT STYLES SETTINGS MANIFEST MIMETYPE
85  
86 text_segment TEXT_SEGMENT
87  
88 input_conversion output_conversion search_string count_substrings
89 color_code color_name load_color_map unload_color_map
90 is_numeric iso_date numeric_date check_odf_value odf_value
91 file_parse file_type load_file image_size input_2d_value
92 alert not_implemented
93 fake_smartmatch
94  
95 XML_PRETTY_PRINT PRETTY_PRINT EMPTY_TAGS
96  
97 FIRST_CHILD LAST_CHILD NEXT_SIBLING PREV_SIBLING WITHIN PARENT
98 );
99  
100 #=== package name aliases ====================================================
101 #--- ODF package & parts -----------------------------------------------------
102  
103 use constant
104 2 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
105 2 odf_document => 'ODF::lpOD::Document',
106 odf_container => 'ODF::lpOD::Container',
107 odf_xmlpart => 'ODF::lpOD::XMLPart',
108 odf_content => 'ODF::lpOD::Content',
109 odf_styles => 'ODF::lpOD::Styles',
110 odf_meta => 'ODF::lpOD::Meta',
111 odf_settings => 'ODF::lpOD::Settings',
112 odf_manifest => 'ODF::lpOD::Manifest'
113 2 };
114  
115 #--- ODF element -------------------------------------------------------------
116  
117 use constant
118 2 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
119 2 odf_element => 'ODF::lpOD::Element',
120 odf_text_node => 'ODF::lpOD::TextNode',
121 odf_text_element => 'ODF::lpOD::TextElement',
122 odf_text_hyperlink => 'ODF::lpOD::TextHyperlink',
123 odf_paragraph => 'ODF::lpOD::Paragraph',
124 odf_heading => 'ODF::lpOD::Heading',
125 odf_list => 'ODF::lpOD::List',
126 odf_field => 'ODF::lpOD::Field',
127 odf_variable => 'ODF::lpOD::Variable',
128 odf_simple_variable => 'ODF::lpOD::SimpleVariable',
129 odf_user_variable => 'ODF::lpOD::UserVariable',
130 odf_text_field => 'ODF::lpOD::TextField',
131 odf_table => 'ODF::lpOD::Table',
132 odf_table_element => 'ODF::lpOD::TableElement',
133 odf_matrix => 'ODF::lpOD::Matrix',
134 odf_column_group => 'ODF::lpOD::ColumnGroup',
135 odf_row_group => 'ODF::lpOD::RowGroup',
136 odf_column => 'ODF::lpOD::Column',
137 odf_row => 'ODF::lpOD::Row',
138 odf_cell => 'ODF::lpOD::Cell',
139 odf_draw_page => 'ODF::lpOD::DrawPage',
140 odf_shape => 'ODF::lpOD::Shape',
141 odf_area => 'ODF::lpOD::Area',
142 odf_rectangle => 'ODF::lpOD::Rectangle',
143 odf_ellipse => 'ODF::lpOD::Ellipse',
144 odf_vector => 'ODF::lpOD::Vector',
145 odf_line => 'ODF::lpOD::Line',
146 odf_connector => 'ODF::lpOD::Connector',
147 odf_frame => 'ODF::lpOD::Frame',
148 odf_image => 'ODF::lpOD::Image',
149 odf_section => 'ODF::lpOD::Section',
150 odf_bibliography_mark => 'ODF::lpOD::BibliographyMark',
151 odf_note => 'ODF::lpOD::Note',
152 odf_annotation => 'ODF::lpOD::Annotation',
153 odf_changed_region => 'ODF::lpOD::ChangedRegion',
154 odf_font_declaration => 'ODF::lpOD::FontDeclaration',
155 odf_style => 'ODF::lpOD::Style',
156 odf_text_style => 'ODF::lpOD::TextStyle',
157 odf_paragraph_style => 'ODF::lpOD::ParagraphStyle',
158 odf_list_style => 'ODF::lpOD::ListStyle',
159 odf_list_level_style => 'ODF::lpOD::ListLevelStyle',
160 odf_outline_style => 'ODF::lpOD::OutlineStyle',
161 odf_table_style => 'ODF::lpOD::TableStyle',
162 odf_column_style => 'ODF::lpOD::ColumnStyle',
163 odf_row_style => 'ODF::lpOD::RowStyle',
164 odf_cell_style => 'ODF::lpOD::CellStyle',
165 odf_data_style => 'ODF::lpOD::DataStyle',
166 odf_master_page => 'ODF::lpOD::MasterPage',
167 odf_page_layout => 'ODF::lpOD::PageLayout',
168 odf_presentation_page_layout => 'ODF::lpOD::PresentationPageLayout',
169 odf_graphic_style => 'ODF::lpOD::GraphicStyle',
170 odf_gradient => 'ODF::lpOD::Gradient',
171 odf_page_end_style => 'ODF::lpOD::PageEndStyle',
172 odf_drawing_page_style => 'ODF::lpOD::DrawingPageStyle',
173 odf_file_entry => 'ODF::lpOD::FileEntry',
174 odf_toc => 'ODF::lpOD::TOC',
175 odf_named_range => 'ODF::lpOD::NamedRange',
176 odf_structured_container => 'ODF::lpOD::StructuredContainer'
177 2 };
178  
179 #--- basic API shortcuts -----------------------------------------------------
180  
181 use constant
182 2 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
183 2 xelt => 'XML::Twig::Elt',
184 xtwig => 'XML::Twig'
185 2 };
186  
187 #--- lpOD common tools and parameters ----------------------------------------
188  
189 use constant
190 2 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
191 2 lpod_common => 'ODF::lpOD::Common',
192 lpod => 'ODF::lpOD::Common'
193 2 };
194  
195 #--- ODF data types ----------------------------------------------------------
196  
197 2 our @DATA_TYPES = qw(string float currency percentage date time boolean);
198  
199 #--- default string comparison function --------------------------------------
200  
201 0 ▶our $COMPARE = sub { shift cmp shift };
Subroutine __ANON__: not called CC=1 SCAR=1.2
202  
203 #=== common parameters =======================================================
204  
205 use constant # common constants
206 2 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
207 2 TRUE => 1,
208 FALSE => 0,
209 2 };
210  
211 use constant # ODF package parts
212 2 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
213 2 META => 'meta.xml',
214 CONTENT => 'content.xml',
215 STYLES => 'styles.xml',
216 SETTINGS => 'settings.xml',
217 MANIFEST => 'META-INF/manifest.xml',
218 MIMETYPE => 'mimetype'
219 2 };
220  
221 use constant
222 2 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
223 2 TEXT_SEGMENT => '#PCDATA',
224 text_segment => '#PCDATA'
225 2 };
226  
227 use constant # XML::Twig specific
228 2 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
229 2 EMPTY_TAGS => 'normal'
230 2 };
231  
232 use constant # element insert positions
233 2 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
234 2 FIRST_CHILD => 'FIRST_CHILD',
235 LAST_CHILD => 'LAST_CHILD',
236 NEXT_SIBLING => 'NEXT_SIBLING',
237 PREV_SIBLING => 'PREV_SIBLING',
238 WITHIN => 'WITHIN',
239 PARENT => 'PARENT'
240 2 };
241  
242 2 our %ODF_TEMPLATE =
243 (
244 'text' => 'text.odt',
245 'spreadsheet' => 'spreadsheet.ods',
246 'presentation' => 'presentation.odp',
247 'drawing' => 'drawing.odg'
248 );
249  
250 2 our $LINE_BREAK = "\n";
251 2 our $TAB_STOP = "\t";
252  
253 2 our $INSTALLATION_PATH = undef; # lpOD library installation path
254  
255 2 our $LPOD_MARK = '#lpod:mark'; # lpOD session bookmark tag
256 2 our $LPOD_ID = '#lpod:id'; # lpOD XML ID attribute
257 2 our $LPOD_PART = '#lpod:part'; # lpOD link from element to xmlpart
258  
259 #=== common function aliases =================================================
260  
261 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
262 2 *odf_get_document = *ODF::lpOD::Document::get_from_uri;
263 2 *odf_new_document_from_template
264 = *ODF::lpOD::Document::create_from_template;
265 2 *odf_new_document_from_type
266 = *ODF::lpOD::Document::_create;
267 2 *odf_new_document = *ODF::lpOD::Document::_create;
268 2 *odf_create_document = *ODF::lpOD::Document::_create;
269 2 *odf_get_container = *ODF::lpOD::Container::get_from_uri;
270 2 *odf_new_container_from_template
271 = *ODF::lpOD::Container::create_from_template;
272 2 *odf_new_container = *ODF::lpOD::Container::create;
273 2 *odf_new_container_from_type
274 = *ODF::lpOD::Container::create;
275 2 *odf_get_xmlpart = *ODF::lpOD::XMLPart::get;
276  
277 2 *odf_create_element = *ODF::lpOD::Element::_create;
278 2 *odf_create_paragraph = *ODF::lpOD::Paragraph::_create;
279 2 *odf_create_heading = *ODF::lpOD::Heading::_create;
280 2 *odf_create_field = *ODF::lpOD::Field::_create;
281 2 *odf_create_simple_variable
282 = *ODF::lpOD::SimpleVariable::_create;
283 2 *odf_create_user_variable
284 = *ODF::lpOD::UserVariable::_create;
285 2 *odf_create_table = *ODF::lpOD::Table::_create;
286 2 *odf_create_row_group = *ODF::lpOD::RowGroup::_create;
287 2 *odf_create_column_group
288 = *ODF::lpOD::ColumnGroup::_create;
289 2 *odf_create_column = *ODF::lpOD::Column::_create;
290 2 *odf_create_row = *ODF::lpOD::Row::_create;
291 2 *odf_create_cell = *ODF::lpOD::Cell::_create;
292 2 *odf_create_section = *ODF::lpOD::Section::_create;
293 2 *odf_create_list = *ODF::lpOD::List::_create;
294 2 *odf_create_draw_page = *ODF::lpOD::DrawPage::_create;
295 2 *odf_create_shape = *ODF::lpOD::Shape::_create;
296 2 *odf_create_area = *ODF::lpOD::Area::_create;
297 2 *odf_create_rectangle = *ODF::lpOD::Rectangle::_create;
298 2 *odf_create_ellipse = *ODF::lpOD::Ellipse::_create;
299 2 *odf_create_vector = *ODF::lpOD::Vector::_create;
300 2 *odf_create_line = *ODF::lpOD::Line::_create;
301 2 *odf_create_connector = *ODF::lpOD::Connector::_create;
302 2 *odf_create_frame = *ODF::lpOD::Frame::_create;
303 2 *odf_create_image = *ODF::lpOD::Image::_create;
304 2 *odf_create_text_frame = *ODF::lpOD::Frame::_create_text;
305 2 *odf_create_image_frame = *ODF::lpOD::Frame::_create_image;
306 2 *odf_create_note = *ODF::lpOD::Note::_create;
307 2 *odf_create_annotation = *ODF::lpOD::Annotation::_create;
308 2 *odf_create_font_declaration
309 = *ODF::lpOD::FontDeclaration::_create;
310 2 *odf_create_style = *ODF::lpOD::Style::_create;
311 2 *odf_classify_text_field
312 = *ODF::lpOD::TextField::classify;
313 2 *odf_create_toc = *ODF::lpOD::TOC::_create;
314  
315 2 *is_numeric = *Scalar::Util::looks_like_number;
316 2 *odf_value = *check_odf_value;
317  
318 2 *PRETTY_PRINT = *XML_PRETTY_PRINT;
319 #initializations
320  
321 }
322  
323 #=== exported utilities ======================================================
324  
325 2 our $DEBUG = FALSE;
326  
327 sub alert
328 0 ▶ {
Subroutine alert: not called CC=3 SCAR=24.8
Pod undocumented
329 0 ▶ if ($DEBUG)
Branch: 1 branch
BranchTrueFalseTotal
if ($ODF::lpOD::Common::DEBUG) 0 0 0
330 {
331 0 require Carp;
332 0 return Carp::cluck(@_);
333 }
334 0 warn "$_\n" for @_;
335 }
336  
337 sub info
338 0 ▶ {
Subroutine info: not called CC=2 SCAR=17.9
Pod undocumented
339 return wantarray ?
340 (
341 0 ▶ name => "ODF::lpOD",
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
342 version => $ODF::lpOD::VERSION,
343 date => ODF::lpOD->PACKAGE_DATE,
344 path => lpod->installation_path
345 )
346 :
347 "ODF::lpOD $ODF::lpOD::VERSION" .
348 " " . ODF::lpOD->PACKAGE_DATE .
349 " " . lpod->installation_path;
350 }
351  
352 0 ▶sub signature { scalar lpod->info }
Subroutine signature: not called CC=1 SCAR=6.9
Pod undocumented
353  
354 sub debug
355 0 ▶ {
Subroutine debug: not called CC=6 SCAR=37.4
Pod undocumented
356 0 ▶ my $param = shift // "";
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
357 0 ▶ $param = shift if $param eq lpod;
Branch: 1 branch
BranchTrueFalseTotal
if $param eq "ODF::lpOD::Common" 0 0 0
358 0 ▶ if (! defined $param)
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $param) { } 0 0 0
elsif ($param == 1 or $param == 0) { } 0 0 0
359 {}
360 ▶ elsif ($param == TRUE || $param == FALSE)
Condition0%0/3
$param == 1 or $param == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$param == 1 or $param == 0
$param == 1 $param == 0
Truth table0%0/3
A or B
A= $param == 1B= $param == 0
ABresult
1X1
011
000
361 0 { $DEBUG = $_; }
362 else
363 0 { alert "Wrong argument"; }
364 0 return $DEBUG;
365 }
366  
367 sub is_true
368 0 ▶ {
Subroutine is_true: not called CC=5 SCAR=34.0
Pod documented
369 0 my $arg = shift;
370 0 ▶ return FALSE unless $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg 0 0 0
371 0 my $v = lc $arg;
372 0 ▶ return $v eq "false" || $v eq "off" || $v eq "no" ? FALSE : TRUE;
Branch: 1 branch
BranchTrueFalseTotal
$v eq 'false' || $v eq 'off' || $v eq 'no' ? : 0 0 0
Condition0%0/6
$v eq "false" or $v eq "off" or $v eq "no"
l!l&&r!l&&!r
000
$v eq "false" or $v eq "off"
l!l&&r!l&&!r
000
MC/DC0%0/3
$v eq "false" or $v eq "off" or $v eq "no"
$v eq "false" $v eq "off" $v eq "no"
Truth table0%0/4
A or B or C
A= $v eq "false"B= $v eq "off"C= $v eq "no"
ABCresult
1XX1
01X1
0011
0000
373 }
374  
375 sub is_false
376 0 ▶ {
Subroutine is_false: not called CC=2 SCAR=17.9
Pod documented
377 0 ▶ return is_true(shift) ? FALSE : TRUE;
Branch: 1 branch
BranchTrueFalseTotal
is_true(shift()) ? : 0 0 0
378 }
379  
380 sub defined_false
381 0 ▶ {
Subroutine defined_false: not called CC=3 SCAR=24.8
Pod undocumented
382 0 my $arg = shift;
383 0 ▶ return FALSE unless defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 0 0 0
384 0 ▶ return is_false($arg) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
is_false($arg) ? : 0 0 0
385 }
386  
387 sub odf_boolean
388 0 ▶ {
Subroutine odf_boolean: not called CC=3 SCAR=24.8
Pod documented
389 0 my $value = shift;
390 0 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
391 0 ▶ return is_true($value) ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
is_true($value) ? : 0 0 0
392 }
393  
394 sub is_odf_datatype
395 0 ▶ {
Subroutine is_odf_datatype: not called CC=3 SCAR=24.8
Pod documented
396 0 ▶ my $type = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $type = shift() or return undef 0 0 0
397 0 ▶ return grep($type eq $_, @DATA_TYPES) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
grep(($type eq $_), @ODF::lpOD::Common::DATA_TYPES) ? : 0 0 0
398 }
399  
400 sub check_odf_value
401 0 ▶ {
Subroutine check_odf_value: not called CC=11 SCAR=48.8
Pod undocumented
402 0 my $value = shift;
403 0 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
404 0 my $type = shift;
405 0 ▶ if ($type eq 'float' || $type eq 'currency' || $type eq 'percentage')
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'float' or $type eq 'currency' or $type eq 'percentage') { } 0 0 0
elsif ($type eq 'boolean') { } 0 0 0
elsif ($type eq 'date') { } 0 0 0
Condition0%0/6
$type eq "float" or $type eq "currency" or $type eq "percentage"
l!l&&r!l&&!r
000
$type eq "float" or $type eq "currency"
l!l&&r!l&&!r
000
MC/DC0%0/3
$type eq "float" or $type eq "currency" or $type eq "percentage"
$type eq "float" $type eq "currency" $type eq "percentage"
Truth table0%0/4
A or B or C
A= $type eq "float"B= $type eq "currency"C= $type eq "percentage"
ABCresult
1XX1
01X1
0011
0000
406 {
407 0 ▶ $value = undef unless is_numeric($value);
Branch: 1 branch
BranchTrueFalseTotal
unless &is_numeric($value) 0 0 0
408 }
409 elsif ($type eq 'boolean')
410 {
411 0 ▶ if (is_true($value))
Branch: 1 branch
BranchTrueFalseTotal
if (is_true($value)) { } 0 0 0
412 {
413 0 $value = 'true';
414 }
415 else {
416 0 $value = 'false';
417 }
418 }
419 elsif ($type eq 'date')
420 {
421 0 ▶ if (is_numeric($value))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_numeric($value)) { } 0 0 0
422 {
423 0 $value = iso_date($value);
424 }
425 else {
426 0 my $num = numeric_date($value);
427 0 ▶ $value = defined $num ? iso_date($num) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $num ? : 0 0 0
428 }
429 }
430 0 return $value;
431 }
432  
433 sub process_options
434 0 ▶ {
Subroutine process_options: not called CC=2 SCAR=17.9
Pod undocumented
435 0 my %in = (@_);
436 0 my %out = ();
437 0 foreach my $ink (keys %in)
438 {
439 0 my $outk = $ink;
440 0 $outk =~ s/[ -]/_/g;
441 0 $out{$outk} = $in{$ink};
442 }
443 0 return %out;
444 }
445  
446 sub alpha_to_num
447 0 ▶ {
Subroutine alpha_to_num: not called CC=7 SCAR=40.3
Pod undocumented
448 0 ▶ my $arg = shift or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $arg = shift() or return 0 0 0 0
449 0 ▶ $arg = shift if ref($arg) || $arg eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg or $arg eq __PACKAGE__ 0 0 0
Condition0%0/3
ref $arg or $arg eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $arg or $arg eq __PACKAGE__
ref $arg $arg eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $argB= $arg eq __PACKAGE__
ABresult
1X1
011
000
450 0 my $alpha = uc $arg;
451 0 ▶ unless ($alpha =~ /^[A-Z]*$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($alpha =~ /^[A-Z]*$/) 0 0 0
452 {
453 0 ▶ return $arg if $alpha =~ /^[0-9\-]*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $alpha =~ /^[0-9\-]*$/ 0 0 0
454 0 alert "Wrong alpha value $arg";
455 0 return undef;
456 }
457 0 my @asplit = split('', $alpha);
458 0 my $num = 0;
459 0 foreach my $p (@asplit)
460 {
461 0 $num *= 26;
462 0 $num += ((ord($p) - ord('A')) + 1);
463 }
464 0 $num--;
465 0 return $num;
466 }
467  
468 sub translate_coordinates # adapted from OpenOffice::OODoc (Genicorp)
469 0 ▶ {
Subroutine translate_coordinates: not called CC=10 SCAR=47.0
Pod documented
470 0 ▶ my $arg = shift // return undef;
Condition0%0/2
shift() // (return undef)
l!l
00
MC/DC0%0/1
shift() // (return undef)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
471 0 my $ra = ref $arg;
472 0 ▶ if ($ra)
Branch: 2 branches
BranchTrueFalseTotal
if ($ra) { } 0 0 0
elsif ($arg eq __PACKAGE__) { } 0 0 0
473 {
474 0 ▶ if ($ra eq 'ARRAY') { return @$arg }
Branch: 1 branch
BranchTrueFalseTotal
if ($ra eq 'ARRAY') { } 0 0 0
475 0 else { shift }
476 }
477 elsif ($arg eq __PACKAGE__)
478 {
479 shift
480 0 }
481 0 ▶ return ($arg, @_) unless defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 0 0 0
482 0 my $coord = uc $arg;
483 0 ▶ return ($arg, @_) unless $coord =~ /[A-Z]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $coord =~ /[A-Z]/ 0 0 0
484  
485 0 $coord =~ s/\s*//g;
486 0 $coord =~ /(^[A-Z]*)(\d*)/;
487 0 my $c = $1;
488 0 my $r = $2;
489 0 ▶ return ($arg, @_) unless $c;
Branch: 1 branch
BranchTrueFalseTotal
unless $c 0 0 0
490 0 my $colnum = alpha_to_num($c);
491 0 ▶ if (defined $r and $r gt "")
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r and $r gt '') { } 0 0 0
Condition0%0/3
defined $r and $r gt ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $r and $r gt ""
defined $r $r gt ""
Truth table0%0/3
A and B
A= defined $rB= $r gt ""
ABresult
0X0
100
111
492 {
493 0 $r--;
494 0 return ($r, $colnum, @_);
495 }
496 else
497 {
498 0 return ($colnum, @_);
499 }
500 }
501  
502 sub translate_range
503 0 ▶ {
Subroutine translate_range: not called CC=7 SCAR=40.3
Pod documented
504 0 ▶ my $arg = shift // return undef;
Condition0%0/2
shift() // (return undef)
l!l
00
MC/DC0%0/1
shift() // (return undef)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
505 0 ▶ $arg = shift if ref($arg) || $arg eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg or $arg eq __PACKAGE__ 0 0 0
Condition0%0/3
ref $arg or $arg eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $arg or $arg eq __PACKAGE__
ref $arg $arg eq __PACKAGE__
Truth table0%0/3
A or B
A= ref $argB= $arg eq __PACKAGE__
ABresult
1X1
011
000
506 0 ▶ return ($arg, @_) unless (defined $arg && $arg =~ /:/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg and $arg =~ /:/ 0 0 0
Condition0%0/3
defined $arg and $arg =~ /:/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $arg and $arg =~ /:/
defined $arg $arg =~ /:/
Truth table0%0/3
A and B
A= defined $argB= $arg =~ /:/
ABresult
0X0
100
111
507 0 my $range = uc $arg;
508 0 $range =~ s/\s*//g;
509 0 my ($start, $end) = split(':', $range);
510 0 my @r = ();
511 0 push @r, translate_coordinates($_) for ($start, $end);
512 0 return @r;
513 }
514  
515 #--- external character set conversion utilities -----------------------------
516  
517 2 our $INPUT_CHARSET = 'utf8';
518 2 our $OUTPUT_CHARSET = 'utf8';
519 2 our $INPUT_ENCODER = Encode::find_encoding($INPUT_CHARSET);
520 2 our $OUTPUT_ENCODER = Encode::find_encoding($OUTPUT_CHARSET);
521  
522 0 ▶sub get_input_charset { $INPUT_CHARSET }
Subroutine get_input_charset: not called CC=1 SCAR=6.9
Pod undocumented
523  
524 0 ▶sub get_output_charset { $OUTPUT_CHARSET }
Subroutine get_output_charset: not called CC=1 SCAR=6.9
Pod undocumented
525  
526 sub set_input_charset
527 0 ▶ {
Subroutine set_input_charset: not called CC=4 SCAR=30.0
Pod undocumented
528 0 ▶ my $charset = shift // "";
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
529 0 ▶ $charset = shift if ($charset eq lpod);
Branch: 1 branch
BranchTrueFalseTotal
if $charset eq "ODF::lpOD::Common" 0 0 0
530 0 my $enc = Encode::find_encoding($charset);
531 0 ▶ unless ($enc)
Branch: 1 branch
BranchTrueFalseTotal
unless ($enc) 0 0 0
532 {
533 0 alert("Unsupported $charset input character set");
534 0 return FALSE;
535 }
536 0 $INPUT_ENCODER = $enc;
537 0 $INPUT_CHARSET = $charset;
538 0 return $INPUT_CHARSET;
539 }
540  
541 sub set_output_charset
542 0 ▶ {
Subroutine set_output_charset: not called CC=4 SCAR=30.0
Pod undocumented
543 0 ▶ my $charset = shift // "";
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
544 0 ▶ $charset = shift if ($charset eq lpod);
Branch: 1 branch
BranchTrueFalseTotal
if $charset eq "ODF::lpOD::Common" 0 0 0
545 0 my $enc = Encode::find_encoding($charset);
546 0 ▶ unless ($enc)
Branch: 1 branch
BranchTrueFalseTotal
unless ($enc) 0 0 0
547 {
548 0 alert("Unsupported output character set");
549 0 return FALSE;
550 }
551 0 $OUTPUT_ENCODER = $enc;
552 0 $OUTPUT_CHARSET = $charset;
553 0 return $OUTPUT_CHARSET;
554 }
555  
556 sub input_conversion
557 0 ▶ {
Subroutine input_conversion: not called CC=4 SCAR=30.0
Pod undocumented
558 0 my $text = shift;
559 0 ▶ return $text unless $INPUT_CHARSET;
Branch: 1 branch
BranchTrueFalseTotal
unless $ODF::lpOD::Common::INPUT_CHARSET 0 0 0
560  
561 0 ▶ unless ($INPUT_ENCODER)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ODF::lpOD::Common::INPUT_ENCODER) 0 0 0
562 {
563 0 alert "Unsupported input character conversion";
564 0 return $text;
565 }
566 0 ▶ return (defined $text) ? $INPUT_ENCODER->decode($text) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 0 0 0
567 }
568  
569 sub output_conversion
570 0 ▶ {
Subroutine output_conversion: not called CC=4 SCAR=30.0
Pod undocumented
571 0 my $text = shift;
572 0 ▶ return $text unless $OUTPUT_CHARSET;
Branch: 1 branch
BranchTrueFalseTotal
unless $ODF::lpOD::Common::OUTPUT_CHARSET 0 0 0
573  
574 0 ▶ unless ($OUTPUT_ENCODER)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ODF::lpOD::Common::OUTPUT_ENCODER) 0 0 0
575 {
576 0 alert "Unsupported output character conversion";
577 0 return $text;
578 }
579  
580 0 ▶ return (defined $text) ? $OUTPUT_ENCODER->encode($text) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 0 0 0
581 }
582  
583 #--- ISO-9601 / internal date conversion -------------------------------------
584  
585 sub iso_date
586 0 ▶ {
Subroutine iso_date: not called CC=2 SCAR=17.9
Pod documented
587 0 ▶ my $time = shift // time();
Condition0%0/2
shift() // time
l!l
00
MC/DC0%0/1
shift() // time
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
588 0 my @t = localtime($time);
589 0 return sprintf
590 (
591 "%04d-%02d-%02dT%02d:%02d:%02d",
592 $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0]
593 );
594 }
595  
596 sub numeric_date # in progress
597 0 ▶ {
Subroutine numeric_date: not called CC=9 SCAR=45.0
Pod documented
598 0 require Time::Local;
599  
600 0 ▶ my $iso_date = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $iso_date = shift() or return undef 0 0 0
601 0 ▶ $iso_date .= 'T00:00:00'unless ($iso_date =~ /T/);
Branch: 1 branch
BranchTrueFalseTotal
unless $iso_date =~ /T/ 0 0 0
602 0 $iso_date =~ /(\d*)-(\d*)-(\d*)T(\d*):(\d*):(\d*)/;
603 0 ▶ my $sec = $6 || 0; my $min = $5 || 0; my $hrs = $4 || 0;
Condition0%0/6
$6 || 0
l!l
00
$5 || 0
l!l
00
$4 || 0
l!l
00
MC/DC0%0/1
$6 || 0
$6
MC/DC0%0/1
$5 || 0
$5
MC/DC0%0/1
$4 || 0
$4
Truth table0%0/2
A
A= $6
Aresult
11
00
Truth table0%0/2
A
A= $5
Aresult
11
00
Truth table0%0/2
A
A= $4
Aresult
11
00
604 0 ▶ my $day = $3 || 1; my $mon = $2 || 1; my $year = $1 || 0;
Condition0%0/6
$3 || 1
l!l
00
$2 || 1
l!l
00
$1 || 0
l!l
00
MC/DC0%0/1
$3 || 1
$3
MC/DC0%0/1
$2 || 1
$2
MC/DC0%0/1
$1 || 0
$1
Truth table0%0/2
A
A= $3
Aresult
11
00
Truth table0%0/2
A
A= $2
Aresult
11
00
Truth table0%0/2
A
A= $1
Aresult
11
00
605 0 return Time::Local::timelocal($sec,$min,$hrs,$day,$mon-1,$year);
606 }
607  
608 #-----------------------------------------------------------------------------
609  
610 sub count_substrings
611 0 ▶ {
Subroutine count_substrings: not called CC=2 SCAR=17.9
Pod undocumented
612 0 my $content = shift;
613 0 my $expr = shift;
614 0 ▶ return undef unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 0 0
615 0 my @matches = ($content =~ /$expr/g);
616 0 return scalar @matches;
617 }
618  
619 sub search_string
620 0 ▶ {
Subroutine search_string: not called CC=14 SCAR=53.5
Pod undocumented
621 0 my $content = shift;
622 0 my $expr = shift;
623 0 ▶ return undef unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 0 0
624 0 my %opt =
625 (
626 replace => undef,
627 offset => undef,
628 range => undef,
629 @_
630 );
631 0 my $start = $opt{offset};
632 0 my $ln = length($content);
633 0 ▶ if ((defined $start) and (abs($start) >= $ln))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start and abs $start >= $ln) 0 0 0
Condition0%0/3
defined $start and abs $start >= $ln
!ll&&!rl&&r
000
MC/DC0%0/2
defined $start and abs $start >= $ln
defined $start abs $start >= $ln
Truth table0%0/3
A and B
A= defined $startB= abs $start >= $ln
ABresult
0X0
100
111
634 {
635 0 alert "[$start $ln] out of range";
636 0 return undef;
637 }
638 0 my $range = $opt{range};
639 0 ▶ if (defined $start)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start) 0 0 0
640 {
641 0 ▶ $start = $start + $ln if $start < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $start < 0 0 0 0
642 0 ▶ $content = defined $range ?
Branch: 1 branch
BranchTrueFalseTotal
defined $range ? : 0 0 0
643 substr($content, $start, $range) :
644 substr($content, $start);
645 }
646 0 ▶ unless (defined $opt{replace})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{'replace'}) { } 0 0 0
647 {
648 0 ▶ if ($content =~ /$expr/)
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /$expr/) { } 0 0 0
649 {
650 0 my $start_pos = length($`);
651 0 ▶ $start_pos += $start if defined $start;
Branch: 1 branch
BranchTrueFalseTotal
if defined $start 0 0 0
652 0 my $end_pos = $start_pos + length($&);
653 0 my $match = $&;
654 return wantarray ?
655 0 ▶ ($start_pos, $end_pos, $match) :
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
656 $start_pos;
657 }
658 else
659 {
660 0 ▶ return wantarray ? (undef) : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
661 }
662 }
663 else
664 {
665 0 my $rep = $opt{replace};
666 0 my $count = ($content =~ s/$expr/$rep/g);
667 0 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
668 {
669 0 return ($content, $count);
670 }
671 else
672 {
673 0 ▶ return $count ? $content : undef;
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 0 0 0
674 }
675 }
676 }
677  
678 #-----------------------------------------------------------------------------
679  
680 sub file_type
681 0 ▶ {
Subroutine file_type: not called CC=3 SCAR=24.8
Pod documented
682 0 require File::Type;
683 0 my $f = shift;
684 0 ▶ return undef unless (-r $f && -f $f);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $f and -f $f 0 0 0
Condition0%0/3
-r $f and -f $f
!ll&&!rl&&r
000
MC/DC0%0/2
-r $f and -f $f
-r $f -f $f
Truth table0%0/3
A and B
A= -r $fB= -f $f
ABresult
0X0
100
111
685 0 return File::Type->new->mime_type($f);
686 }
687  
688 sub file_parse
689 0 ▶ {
Subroutine file_parse: not called CC=3 SCAR=24.8
Pod documented
690 0 require File::Basename;
691 0 my $source = shift;
692 0 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 0 0
693 {
694 0 my ($name,$path,$suffix) =
695 File::Basename::fileparse($source, qr/\.[^.]*/);
696 0 ▶ if (defined $suffix)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $suffix) 0 0 0
697 {
698 0 $name .= $suffix;
699 0 $suffix =~ s/^\.//;
700 }
701 0 return ($name, $path, $suffix);
702 }
703 0 return File::Basename::fileparse($source);
704 }
705  
706 sub load_file
707 0 ▶ {
Subroutine load_file: not called CC=8 SCAR=42.8
Pod undocumented
708 0 ▶ my $url = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $url = shift() or return undef 0 0 0
709 0 ▶ my $mode = shift // ':utf8';
Condition0%0/2
shift() // ":utf8"
l!l
00
MC/DC0%0/1
shift() // ":utf8"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
710  
711 0 ▶ if (! ref $url and $url =~ /:/ and uc($url) !~ /^[A-Z]:/)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $url and $url =~ /:/ and not uc($url) =~ /^[A-Z]:/) { } 0 0 0
Condition0%0/6
not ref $url and $url =~ /:/ and not uc($url) =~ /^[A-Z]:/
!ll&&!rl&&r
000
not ref $url and $url =~ /:/
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $url and $url =~ /:/ and not uc($url) =~ /^[A-Z]:/
not ref $url $url =~ /:/ not uc($url) =~ /^[A-Z]:/
Truth table0%0/4
not(A) and B and not(C)
A= not ref $urlB= $url =~ /:/C= not uc($url) =~ /^[A-Z]:/
ABCresult
0XX0
10X0
1100
1111
712 {
713 0 require LWP::Simple;
714 0 $url =~ s{\\}{/};
715 0 return LWP::Simple::get($url);
716 }
717 else
718 {
719 0 ▶ return undef unless ref $url or -r -f -e $url;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $url or -r -f -e $url 0 0 0
Condition0%0/3
ref $url or -r -f -e $url
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $url or -r -f -e $url
ref $url -r -f -e $url
Truth table0%0/3
A or B
A= ref $urlB= -r -f -e $url
ABresult
1X1
011
000
720 0 require File::Slurp;
721 0 return scalar File::Slurp::read_file
722 ($url, binmode => $mode);
723 }
724 }
725  
726 sub image_size
727 0 ▶ {
Subroutine image_size: not called CC=7 SCAR=40.3
Pod documented
728 0 ▶ my $url = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $url = shift() or return undef 0 0 0
729 0 my %opt = @_;
730 0 my $source;
731  
732 0 ▶ if (ref $url eq 'SCALAR')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $url eq 'SCALAR') { } 0 0 0
elsif ($opt{'document'}) { } 0 0 0
733 {
734 0 $source = $url;
735 }
736 elsif ($opt{document})
737 {
738 0 $source = \($opt{document}->get_part($url));
739 }
740 else
741 {
742 0 $source = \(load_file($url, ':raw'));
743 }
744  
745 0 ▶ if ($source)
Branch: 1 branch
BranchTrueFalseTotal
if ($source) { } 0 0 0
746 {
747 0 require Image::Size;
748 0 my ($w, $h) = Image::Size::imgsize($source);
749 0 ▶ return undef unless defined $w;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w 0 0 0
750 0 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
751 {
752 0 return ($w, $h);
753 }
754 else
755 {
756 0 $w .= 'pt'; $h .= 'pt';
757 0 return [$w, $h];
758 }
759 }
760 else
761 {
762 0 return undef;
763 }
764 }
765  
766 sub input_2d_value
767 0 ▶ {
Subroutine input_2d_value: not called CC=11 SCAR=48.8
Pod undocumented
768 0 ▶ my $arg = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $arg = shift() or return undef 0 0 0
769 0 ▶ my $u = shift // 'cm';
Condition0%0/2
shift() // "cm"
l!l
00
MC/DC0%0/1
shift() // "cm"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
770 0 my ($x, $y);
771 0 ▶ if (ref $arg)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg) { } 0 0 0
elsif ($arg) { } 0 0 0
772 {
773 0 $x = $arg->[0]; $y = $arg->[1];
774 }
775 elsif ($arg)
776 {
777 0 ▶ if ($arg =~ /,/)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /,/) { } 0 0 0
778 {
779 0 $arg =~ s/\s*//g;
780 0 ($x, $y) = split(',', $arg);
781 }
782 else
783 {
784 0 $x = $arg; $y = shift;
785 }
786 }
787 0 ▶ $x ||= ('0' . $u); $y ||= ('0' . $u);
Condition0%0/6
$x ||= '0' . $u
l!l&&r!l&&!r
000
$y ||= '0' . $u
l!l&&r!l&&!r
000
MC/DC0%0/2
$x ||= '0' . $u
$x '0' . $u
MC/DC0%0/2
$y ||= '0' . $u
$y '0' . $u
Truth table0%0/3
A ||= B
A= $xB= '0' . $u
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $yB= '0' . $u
ABresult
1X1
011
000
788 0 ▶ $x .= $u unless $x =~ /[a-zA-Z]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $x =~ /[a-zA-Z]$/ 0 0 0
789 0 ▶ $y .= $u unless $y =~ /[a-zA-Z]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $y =~ /[a-zA-Z]$/ 0 0 0
790 0 ▶ return wantarray ? ($x, $y) : [$x, $y];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
791 }
792  
793 #--- symbolic color names handling -------------------------------------------
794  
795 2 our %COLORCODE = ();
796 2 our %COLORNAME = ();
797  
798 sub color_code
799 0 ▶ {
Subroutine color_code: not called CC=4 SCAR=30.0
Pod undocumented
800 0 ▶ my $name = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $name = shift() or return undef 0 0 0
801 0 ▶ if ($name && ($name =~ /^#/)) { return $name }
Branch: 1 branch
BranchTrueFalseTotal
if ($name and $name =~ /^#/) 0 0 0
Condition0%0/3
$name and $name =~ /^#/
!ll&&!rl&&r
000
MC/DC0%0/2
$name and $name =~ /^#/
$name $name =~ /^#/
Truth table0%0/3
A and B
A= $nameB= $name =~ /^#/
ABresult
0X0
100
111
802 0 return $COLORCODE{$name};
803 }
804  
805 sub color_name
806 0 ▶ {
Subroutine color_name: not called CC=2 SCAR=17.9
Pod undocumented
807 0 ▶ my $code = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $code = shift() or return undef 0 0 0
808 0 return $COLORNAME{lc $code};
809 }
810  
811 sub load_color_map
812 0 ▶ {
Subroutine load_color_map: not called CC=9 SCAR=45.0
Pod undocumented
813 0 ▶ my $filename = shift || (installation_path() . '/data/rgb.txt');
Condition0%0/2
shift() || installation_path() . '/data/rgb.txt'
l!l
00
MC/DC0%0/1
shift() || installation_path() . '/data/rgb.txt'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
814 0 ▶ unless ( -e $filename && -r $filename )
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $filename and -r $filename) 0 0 0
Condition0%0/3
-e $filename and -r $filename
!ll&&!rl&&r
000
MC/DC0%0/2
-e $filename and -r $filename
-e $filename -r $filename
Truth table0%0/3
A and B
A= -e $filenameB= -r $filename
ABresult
0X0
100
111
815 {
816 0 ▶ warn "Color map file non existent or unreadable"
Branch: 1 branch
BranchTrueFalseTotal
if $ODF::lpOD::Common::DEBUG 0 0 0
817 if $DEBUG;
818 0 return FALSE;
819 }
820 0 my $r = open COLORS, "<", $filename;
821 0 ▶ unless ($r)
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
822 {
823 0 alert "Error opening $filename"; return FALSE;
824 }
825 0 ▶ while (my $line = <COLORS>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline COLORS)) 0 0 0
826 {
827 0 $line =~ s/^\s*//; $line =~ s/\s*$//;
828 0 ▶ next unless $line =~ /^[0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^[0-9]/ 0 0 0
829 0 $line =~ /(\d*)\s*(\d*)\s*(\d*)\s*(.*)/;
830 0 my $name = $4;
831 0 ▶ $COLORCODE{$name} = sprintf("#%02x%02x%02x", $1, $2, $3)
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
832 if $name;
833 }
834 0 close COLORS;
835 0 %COLORNAME = reverse %COLORCODE;
836 0 return TRUE;
837 }
838  
839 sub unload_color_map
840 0 ▶ {
Subroutine unload_color_map: not called CC=1 SCAR=6.9
Pod undocumented
841 0 my $self = shift;
842 0 %COLORCODE = ();
843 0 %COLORNAME = ();
844 0 return TRUE;
845 }
846  
847 #-----------------------------------------------------------------------------
848  
849 0 ▶sub installation_path { $INSTALLATION_PATH }
Subroutine installation_path: not called CC=1 SCAR=6.9
Pod undocumented
850  
851 sub template
852 0 ▶ {
Subroutine template: not called CC=5 SCAR=34.0
Pod undocumented
853 0 ▶ my $type = shift // "";
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
854 0 ▶ $type = shift if $type eq lpod;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "ODF::lpOD::Common" 0 0 0
855  
856 0 my $filename = $ODF_TEMPLATE{$type};
857 0 ▶ unless ($filename)
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename) 0 0 0
858 {
859 0 alert("Unsupported type");
860 0 return FALSE;
861 }
862 0 my $fullpath = installation_path() . '/templates/' . $filename;
863 0 ▶ unless (-r -f -e $fullpath)
Branch: 1 branch
BranchTrueFalseTotal
unless (-r -f -e $fullpath) 0 0 0
864 {
865 0 alert("Template not available");
866 0 return FALSE;
867 }
868 0 return $fullpath;
869 }
870  
871 #--- session ID generator ----------------------------------------------------
872  
873 2 our $LPOD_ID_PATTERN = 'lpOD_%09x';
874 sub new_id
875 0 ▶ {
Subroutine new_id: not called CC=1 SCAR=6.9
Pod undocumented
876 0 state $count = 0;
877 0 return sprintf($LPOD_ID_PATTERN, ++$count);
878 }
879  
880 #--- pretty XML output option ------------------------------------------------
881  
882 2 our $XML_PRETTY_PRINT_MODE = 'indented';
883  
884 sub XML_PRETTY_PRINT
885 0 ▶ {
Subroutine XML_PRETTY_PRINT: not called CC=4 SCAR=30.0
Pod undocumented
886 0 ▶ my $pp = shift // "";
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
887 0 ▶ $pp = shift if ($pp eq lpod);
Branch: 1 branch
BranchTrueFalseTotal
if $pp eq "ODF::lpOD::Common" 0 0 0
888 0 ▶ $XML_PRETTY_PRINT_MODE = $pp if $pp;
Branch: 1 branch
BranchTrueFalseTotal
if $pp 0 0 0
889 0 return $XML_PRETTY_PRINT_MODE;
890 }
891  
892 #-----------------------------------------------------------------------------
893  
894 sub not_implemented
895 0 ▶ {
Subroutine not_implemented: not called CC=1 SCAR=6.9
Pod undocumented
896 0 alert("NOT IMPLEMENTED");
897 0 return FALSE;
898 }
899  
900 # Perl 5.38 loudly deprecates 'when' and the ~~ operator, and 5.40 will
901 # supposedly remove them entirely. To preserve existing semantics of
902 # existing code including user-visible functions, a subset of the ~~
903 # operator is included here. Previously this was a custom function
904 # (thanks Jim Avera) but has since been replaced with match::simple
905 sub fake_smartmatch
906 0 ▶ {
Subroutine fake_smartmatch: not called CC=1 SCAR=6.9
Pod undocumented
907 0 return match($_[0], $_[1]);
908 }
909  
910 #=============================================================================
911 2 1;
↑ Summary lpOD/Table.pm »