File Coverage

blib/lib/Data/Embed/Util.pm
Criterion Covered Total %
statement 29 38 76.3
branch 0 4 0.0
condition n/a
subroutine 9 10 90.0
pod 3 3 100.0
total 41 55 74.5


line stmt bran cond sub pod time code
1             package Data::Embed::Util;
2              
3 9     9   30 use strict;
  9         10  
  9         202  
4 9     9   26 use warnings;
  9         8  
  9         179  
5 9     9   24 use English qw< -no_match_vars >;
  9         8  
  9         33  
6 9     9   2340 use Log::Log4perl::Tiny qw< :easy :dead_if_first >;
  9         9  
  9         47  
7              
8             our $VERSION = '0.32'; # make indexer happy
9              
10 9     9   1853 use Exporter qw< import >;
  9         10  
  9         653  
11             our @EXPORT_OK = qw< STARTER TERMINATOR escape unescape transfer >;
12             our @EXPORT = (); # export nothing by default
13             our %EXPORT_TAGS = (
14             all => \@EXPORT_OK,
15             escaping => [qw< escape unescape >],
16             constants => [qw< STARTER TERMINATOR >],
17             );
18              
19 9     9   31 use constant STARTER => "Data::Embed/index/begin\n";
  9         9  
  9         505  
20 9     9   29 use constant TERMINATOR => "Data::Embed/index/end\n";
  9         8  
  9         1875  
21              
22             sub escape {
23 121     121 1 112 my $text = shift;
24 121         477 $text =~ s{([^\w.-])}{'%' . sprintf('%02x', ord $1)}egmxs;
  181         757  
25 121         441 return $text;
26             }
27              
28             sub unescape {
29 16     16 1 12 my $text = shift;
30 16         38 $text =~ s{%(..)}{chr(hex($1))}egmxs;
  22         48  
31 16         32 return $text;
32             }
33              
34             sub transfer {
35 0     0 1   my ($infh, $outfh) = @_;
36 0           while ('necessary') {
37 0           my $buffer;
38 0           my $n = sysread $infh, $buffer, 0, 4096;
39 0 0         LOGCROAK "sysread(): $OS_ERROR" unless defined $n;
40 0 0         last unless $n;
41 0           print {$outfh} $buffer;
  0            
42             } ## end while ('necessary')
43 0           return;
44             } ## end sub transfer
45              
46             1;