Indexed/Utf8.pm

filter: Statementstmt 100% 19 / 19 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 88.5% 31 / 35 CC 5 SCAR 9.6
CC
5
Cov
89%
writeData
4.1
readData
2.0
BEGIN
1.0
CRAP 2.6
« Indexed.pm ↑ Summary Indexed/JSON.pm »
1 ##-*- Mode: CPerl -*-
2 ##
3 ## File: Tie/File/Indexed/Utf8.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: tied array access to indexed data files: utf8-encoded strings
6  
7  
8 package Tie::File::Indexed::Utf8;
9 2 ▶use Tie::File::Indexed;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 ##======================================================================
14 ## Globals
15  
16 2 our @ISA = qw(Tie::File::Indexed);
17  
18 ##======================================================================
19 ## Subclass API: Data I/O: overides
20  
21 ## $bool = $tfi->writeData($utf8_string)
22 ## + override transparently encodes $data as utf8
23 4 ▶sub writeData {
Subroutine writeData: called CC=4 SCAR=14.1
Pod documented
24 4 my $val = $_[1];
25 4 ▶ if (defined($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 4 0 4
26 4 ▶ utf8::upgrade($val) if (!utf8::is_utf8($val)); ##-- convert byte-strings to utf8
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($val) 1 3 4
27 4 utf8::encode($val); ##-- ... but write (encoded) byte-strings
28 }
29 4 ▶ return $_[0]{datfh}->print($val//'');
Condition50%1/2
$val // ""
l!l
40
MC/DC0%0/1
$val // ""
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
30 }
31  
32 ## $data_or_undef = $tfi->readData($length)
33 ## + read item data from $tfi->{datfh} from its current position
34 ## + returned scalars should always have their utf8 flag set
35 4 ▶sub readData {
Subroutine readData: called CC=2 SCAR=7.1
Pod documented
36 4 ▶ defined(my $buf = $_[0]->SUPER::readData($_[1])) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $buf = $_[0]->SUPER::readData($_[1])) or return undef 4 0 4
37 4 utf8::decode($buf);
38 4 return $buf;
39 }
40  
41  
42 2 1; ##-- be happpy
« Indexed.pm ↑ Summary Indexed/JSON.pm »