File Coverage

blib/lib/Encode/JavaScript/UCS.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             package Encode::JavaScript::UCS;
2 2     2   92676 use strict;
  2         10  
  2         924  
3 2     2   927 use 5.8.1;
  2         189  
  2         666  
4             our $VERSION = '0.01';
5              
6 2     2   13 use base qw(Encode::Encoding);
  2         7  
  2         1377  
7 2     2   15833 use Encode 2.12 (); # for callbacks
  2         46  
  2         511  
8              
9             __PACKAGE__->Define('JavaScript-UCS');
10              
11             sub decode($$;$){
12 1     1 1 764 my ($obj, $buf, $chk) = @_;
13 1         7 $buf =~ s/\\u([0-9a-f]{4})/chr(hex($1))/eig;
  4         14  
14 1 50       4 $_[1] = '' if $chk; # this is what in-place edit means
15 1         4 return $buf;
16             }
17              
18             sub encode($$;$){
19 1     1 1 33 my ($obj, $str, $chk) = @_;
20 1     4   7 $str = Encode::encode("ascii", $str, sub { sprintf("\\u%04x", $_[0]) });
  4         47  
21 1 50       11 $_[1] = '' if $chk; # this is what in-place edit means
22 1         3 return $str;
23             }
24              
25             1;
26             __END__