File Coverage

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


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