File Coverage

blib/lib/Mojo/Unicode/UTF8.pm
Criterion Covered Total %
statement 24 24 100.0
branch 6 6 100.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 37 37 100.0


line stmt bran cond sub pod time code
1             package Mojo::Unicode::UTF8;
2              
3 1     1   20791 use strict;
  1         2  
  1         24  
4 1     1   5 use warnings;
  1         2  
  1         28  
5 1     1   1026 use Mojo::Util 'decode', 'encode', 'monkey_patch';
  1         63402  
  1         124  
6 1     1   735 use Unicode::UTF8 'decode_utf8', 'encode_utf8';
  1         461  
  1         124  
7              
8             our $VERSION = '0.002';
9              
10             monkey_patch 'Mojo::Util', 'decode', sub {
11 3 100   3   605 goto &decode unless $_[0] eq 'UTF-8';
12 2         6 my ($encoding, $bytes) = @_;
13 2         3 local $@;
14 2 100       5 return undef unless eval {
15 1     1   5 use warnings FATAL => 'utf8';
  1         2  
  1         135  
16 2         36 $bytes = decode_utf8 $bytes; 1
  1         5  
17             };
18 1         5 return $bytes;
19             };
20              
21             monkey_patch 'Mojo::Util', 'encode', sub {
22 3 100   3   3268 goto &encode unless $_[0] eq 'UTF-8';
23 2         25 return encode_utf8 $_[1];
24             };
25              
26             1;
27              
28             =head1 NAME
29              
30             Mojo::Unicode::UTF8 - use Unicode::UTF8 as the UTF-8 encoder for Mojolicious
31              
32             =head1 SYNOPSIS
33              
34             use Mojo::Unicode::UTF8;
35             use Mojo::Util 'decode', 'encode';
36            
37             # Preload for scripts using Mojo::Util
38             $ perl -MMojo::Unicode::UTF8 $(which morbo) myapp.pl
39            
40             # Must be set in environment for hypnotoad
41             $ PERL5OPT=-MMojo::Unicode::UTF8 hypnotoad myapp.pl
42              
43             =head1 DESCRIPTION
44              
45             L is a monkey-patch module for using L as
46             the UTF-8 encoder for a L application, or anything else using
47             L. It must be loaded before L so the new functions will
48             be properly exported. Calling L or L
49             with any encoding other than C will fall back to L as normal.
50             For details on the benefits, see L.
51              
52             =head1 BUGS
53              
54             Report any issues on the public bugtracker.
55              
56             =head1 AUTHOR
57              
58             Dan Book
59              
60             =head1 COPYRIGHT AND LICENSE
61              
62             This software is Copyright (c) 2015 by Dan Book.
63              
64             This is free software, licensed under:
65              
66             The Artistic License 2.0 (GPL Compatible)
67              
68             =head1 SEE ALSO
69              
70             L, L, L