File Coverage

blib/lib/Data/CompactReadonly/V0/Text.pm
Criterion Covered Total %
statement 28 28 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 36 36 100.0


line stmt bran cond sub pod time code
1             package Data::CompactReadonly::V0::Text;
2             our $VERSION = '0.0.5';
3              
4 9     9   67 use warnings;
  9         18  
  9         344  
5 9     9   50 use strict;
  9         20  
  9         208  
6 9     9   43 use base 'Data::CompactReadonly::V0::Collection';
  9         36  
  9         4551  
7              
8 9     9   5589 use Encode qw(encode decode);
  9         94914  
  9         3096  
9              
10             sub _init {
11 557     557   1977 my($class, %args) = @_;
12 557         1259 my($root, $offset) = @args{qw(root offset)};
13              
14 557         1576 my $length = $class->_numeric_type_for_length()->_init(root => $root, offset => $offset);
15 557         1522 my $value = $class->_bytes_to_text($root->_bytes_at_current_offset($length));
16              
17 557         82247 return $value;
18             }
19              
20             sub _create {
21 65658     65658   217523 my($class, %args) = @_;
22 65658         119027 my $fh = $args{fh};
23 65658         247568 $class->_stash_already_seen(%args);
24 65658         381630 (my $scalar_type = $class) =~ s/Text/Scalar/;
25 65658         205288 my $text = $class->_text_to_bytes($args{data});
26              
27 65658         2942365 print $fh $class->_type_byte_from_class().
28             $scalar_type->_get_bytes_from_word(length($text)).
29             $text;
30 65658         513952 $class->_set_next_free_ptr(%args);
31             }
32              
33             sub _bytes_to_text {
34 557     557   1174 my($invocant, $bytes) = @_;
35 557         1533 return decode('utf-8', $bytes);
36             }
37              
38             sub _text_to_bytes {
39 131316     131316   246953 my($invocant,$text) = @_;
40 131316         340929 return encode('utf-8', $text);
41             }
42              
43             1;