File Coverage

blib/lib/Test/Stream/Plugin/UTF8.pm
Criterion Covered Total %
statement 26 28 92.8
branch 1 4 25.0
condition 2 2 100.0
subroutine 6 6 100.0
pod 0 1 0.0
total 35 41 85.3


line stmt bran cond sub pod time code
1             package Test::Stream::Plugin::UTF8;
2 95     95   684 use strict;
  95         119  
  95         2286  
3 95     95   304 use warnings;
  95         114  
  95         1758  
4              
5 95     95   290 use Test::Stream::Sync();
  95         103  
  95         1313  
6 95     95   295 use Test::Stream::Plugin qw/import/;
  95         113  
  95         507  
7              
8             sub load_ts_plugin {
9 114     114 0 195 my $class = shift;
10 114         169 my ($caller) = @_;
11              
12             # Load and import UTF8 into the caller.
13 114         463 require utf8;
14 114         500 utf8->import;
15              
16             # Set STDERR and STDOUT
17 114         786 binmode(STDERR, ':utf8');
18 114         234 binmode(STDOUT, ':utf8');
19              
20             # Set the output formatters to use utf8
21             Test::Stream::Sync->post_load(sub {
22 112     112   319 my $stack = Test::Stream::Sync->stack;
23 112         594 $stack->top; # Make sure we have at least 1 hub
24              
25 112         132 my $warned = 0;
26 112         414 for my $hub ($stack->all) {
27 116   100     319 my $format = $hub->format || next;
28              
29 112 50       500 unless ($format->can('encoding')) {
30 0 0       0 warn "Could not apply UTF8 to unknown formatter ($format) at $caller->[1] line $caller->[2].\n" unless $warned++;
31 0         0 next;
32             }
33              
34 112         424 $format->encoding('utf8');
35             }
36 114         928 });
37             }
38              
39             1;
40              
41             __END__