blib/lib/Test2/Plugin/UTF8.pm

filter: Statementstmt 88.2% 30 / 34 Branchbran 41.6% 5 / 12 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 80.0% 44 / 55 CC 9 SCAR 15.1
CC
9
Cov
77%
import
5.9
__ANON__
5.9
BEGIN
1.0
CRAP 4.5
« blib/lib/Test2/Util/Table.pm ↑ Summary blib/lib/Test2/AsyncSubtest/Hub.pm »
1 package Test2::Plugin::UTF8;
2 164 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 164 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 164 our $VERSION = '1.302226';
6  
7 164 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 164 ▶use Test2::API qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
10 test2_add_callback_post_load
11 test2_stack
12 164 };
13  
14 164 my $LOADED = 0;
15  
16 317 ▶sub import {
Subroutine import: called CC=5 SCAR=17.8
17 317 my $class = shift;
18  
19 317 my $import_utf8 = 1;
20 317 ▶ while ( my $arg = shift @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift @_) 0 317 317
21 0 ▶ croak "Unsupported import argument '$arg'" unless $arg eq 'encoding_only';
Branch: 1 branch
BranchTrueFalseTotal
unless $arg eq "encoding_only" 0 0 0
22 0 $import_utf8 = 0;
23 }
24  
25 # Load and import UTF8 into the caller.
26 317 ▶ if ( $import_utf8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($import_utf8) 317 0 317
27 317 require utf8;
28 317 utf8->import;
29 }
30  
31 317 ▶ return if $LOADED++; # do not add multiple hooks
Branch: 1 branch
BranchTrueFalseTotal
if $LOADED++ 153 164 317
32  
33 # Set the output formatters to use utf8
34 164 ▶ test2_add_callback_post_load(sub {
Subroutine __ANON__: called CC=5 SCAR=17.8
35 164 my $stack = test2_stack;
36 164 $stack->top; # Make sure we have at least 1 hub
37  
38 164 my $warned = 0;
39 164 for my $hub ($stack->all) {
40 165 ▶ my $format = $hub->format || next;
Condition100%2/2
$hub->format || (next)
l!l
1641
MC/DC100%1/1
$hub->format || (next)
$hub->format
Truth table100%2/2
A
A= $hub->format
Aresult
11
00
41  
42 164 ▶ unless ($format->can('encoding')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($format->can("encoding")) 0 164 164
43 0 ▶ warn "Could not apply UTF8 to unknown formatter ($format)\n" unless $warned++;
Branch: 1 branch
BranchTrueFalseTotal
unless $warned++ 0 0 0
44 0 next;
45 }
46  
47 164 $format->encoding('utf8');
48 }
49 164 });
50 }
51  
52 164 1;
53  
54 __END__
« blib/lib/Test2/Util/Table.pm ↑ Summary blib/lib/Test2/AsyncSubtest/Hub.pm »