| 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
| |||||||||||||
| 26 | 4 | ▶ | utf8::upgrade($val) if (!utf8::is_utf8($val)); ##-- convert byte-strings to utf8 | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 4 | utf8::encode($val); ##-- ... but write (encoded) byte-strings | |||||||||||
| 28 | } | ||||||||||||
| 29 | 4 | ▶ | return $_[0]{datfh}->print($val//''); | ||||||||||
|
Condition50%1/2
$val // ""
MC/DC0%0/1
$val // ""
$val
Truth table50%1/2
A
A= $val
| |||||||||||||
| 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
| |||||||||||||
| 37 | 4 | utf8::decode($buf); | |||||||||||
| 38 | 4 | return $buf; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | |||||||||||||
| 42 | 2 | 1; ##-- be happpy | |||||||||||