| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Test2::Plugin::UTF8; | 
| 2 | 157 |  |  | 157 |  | 2889 | use strict; | 
|  | 157 |  |  |  |  | 3073 |  | 
|  | 157 |  |  |  |  | 4985 |  | 
| 3 | 157 |  |  | 157 |  | 923 | use warnings; | 
|  | 157 |  |  |  |  | 484 |  | 
|  | 157 |  |  |  |  | 6833 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | our $VERSION = '0.000156'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 157 |  |  | 157 |  | 1003 | use Carp qw/croak/; | 
|  | 157 |  |  |  |  | 370 |  | 
|  | 157 |  |  |  |  | 8950 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 157 |  |  |  |  | 47475 | use Test2::API qw{ | 
| 10 |  |  |  |  |  |  | test2_add_callback_post_load | 
| 11 |  |  |  |  |  |  | test2_stack | 
| 12 | 157 |  |  | 157 |  | 2374 | }; | 
|  | 157 |  |  |  |  | 155070 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | my $LOADED = 0; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub import { | 
| 17 | 315 |  |  | 315 |  | 719 | my $class = shift; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 315 |  |  |  |  | 623 | my $import_utf8 = 1; | 
| 20 | 315 |  |  |  |  | 1190 | while ( my $arg = shift @_ ) { | 
| 21 | 0 | 0 |  |  |  | 0 | croak "Unsupported import argument '$arg'" unless $arg eq 'encoding_only'; | 
| 22 | 0 |  |  |  |  | 0 | $import_utf8 = 0; | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | # Load and import UTF8 into the caller. | 
| 26 | 315 | 50 |  |  |  | 1125 | if ( $import_utf8 ) { | 
| 27 | 315 |  |  |  |  | 3103 | require utf8; | 
| 28 | 315 |  |  |  |  | 2121 | utf8->import; | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 315 | 100 |  |  |  | 2181 | return if $LOADED++; # do not add multiple hooks | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # Set the output formatters to use utf8 | 
| 34 |  |  |  |  |  |  | test2_add_callback_post_load(sub { | 
| 35 | 157 |  |  | 157 |  | 52931 | my $stack = test2_stack; | 
| 36 | 157 |  |  |  |  | 2414 | $stack->top; # Make sure we have at least 1 hub | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 157 |  |  |  |  | 3086635 | my $warned = 0; | 
| 39 | 157 |  |  |  |  | 1346 | for my $hub ($stack->all) { | 
| 40 | 157 |  | 50 |  |  | 1636 | my $format = $hub->format || next; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 157 | 50 |  |  |  | 2806 | unless ($format->can('encoding')) { | 
| 43 | 0 | 0 |  |  |  | 0 | warn "Could not apply UTF8 to unknown formatter ($format)\n" unless $warned++; | 
| 44 | 0 |  |  |  |  | 0 | next; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 157 |  |  |  |  | 885 | $format->encoding('utf8'); | 
| 48 |  |  |  |  |  |  | } | 
| 49 | 157 |  |  |  |  | 1977 | }); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | 1; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | __END__ |