| 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__ |