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   1108 use strict;
  95         189  
  95         2594  
3 95     95   498 use warnings;
  95         199  
  95         2568  
4              
5 95     95   543 use Test::Stream::Sync;
  95         184  
  95         1988  
6 95     95   533 use Test::Stream::Plugin;
  95         207  
  95         662  
7              
8             sub load_ts_plugin {
9 113     113 0 285 my $class = shift;
10 113         254 my ($caller) = @_;
11              
12             # Load and import UTF8 into the caller.
13 113         591 require utf8;
14 113         698 utf8->import;
15              
16             # Set STDERR and STDOUT
17 113         916 binmode(STDERR, ':utf8');
18 113         363 binmode(STDOUT, ':utf8');
19              
20             # Set the output formatters to use utf8
21             Test::Stream::Sync->post_load(sub {
22 111     111   493 my $stack = Test::Stream::Sync->stack;
23 111         674 $stack->top; # Make sure we have at least 1 hub
24              
25 111         218 my $warned = 0;
26 111         636 for my $hub ($stack->all) {
27 115   100     488 my $format = $hub->format || next;
28              
29 111 50       738 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 111         525 $format->encoding('utf8');
35             }
36 113         1115 });
37             }
38              
39             1;
40              
41             __END__