List.pm

filter: Statementstmt 78.2% 18 / 23 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 50.0% 1 / 2 totaltotal 72.2% 26 / 36 CC 5 SCAR 14.8
CC
5
Cov
69%
detect_terminal_type
8.1
new
2.1
BEGIN
1.0
CRAP 4.4
« List/Role.pm ↑ Summary
1 package Term::Output::List;
2 3 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Module::Load 'load';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.06';
8  
9 =head1 NAME
10  
11 Term::Output::List - output an updateable list of ongoing jobs
12  
13 =head1 SYNOPSIS
14  
15 my $printer = Term::Output::List->new(
16 hook_warnings => 1,
17 ellipsis => "\N{HORIZONTAL ELLIPSIS}",
18 );
19 my @ongoing_tasks = ('file1: frobnicating', 'file2: bamboozling', 'file3: frobnicating');
20 $printer->output_list(@ongoing_tasks);
21  
22 $printer->output_permanent("Frobnicated gizmos"); # appears above the list
23  
24 =cut
25  
26 2 ▶sub detect_terminal_type($os = $^O) {
Subroutine detect_terminal_type: called CC=4 SCAR=20.9
Pod undocumented
27 2 ▶ if( $os eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($os eq 'MSWin32') { } 0 2 2
28 0 require Win32::Console;
29 0 ▶ if( Win32::Console->Mode & 0x0004 ) { #ENABLE_VIRTUAL_TERMINAL_PROCESSING
Branch: 1 branch
BranchTrueFalseTotal
if ('Win32::Console'->Mode & 4) { } 0 0 0
30 0 return 'ansi';
31 } else {
32 0 return 'win32'
33 }
34 } else {
35 2 return 'ansi';
36 }
37 }
38  
39 2 ▶sub new($class,%args) {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
40 2 my $ttype = detect_terminal_type();
41  
42 2 my $impl = 'Term::Output::List::ANSI';
43 2 ▶ if( $ttype eq 'win32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ttype eq "win32") 0 2 2
44 0 $impl = 'Term::Output::List::Win32';
45 }
46 2 load $impl;
47 2 return $impl->new( %args )
48 }
49  
50 =head1 METHODS
51  
52 =head2 C<< Term::Output::List->new() >>
53  
54 =over 4
55  
56 =item C<< fh >>
57  
58 Filehandle used for output. Default is C<< STDOUT >>.
59  
60 =item C<< interactive >>
61  
62 Whether the script is run interactively and should output intermittent
63 updateable information
64  
65 =item C<< hook_warnings >>
66  
67 Install a hook for sending warnings to C<< ->output_permanent >>. This
68 prevents ugly tearing/overwriting when your code outputs warnings.
69  
70 =back
71  
72 =head2 C<< ->scroll_up >>
73  
74 Helper method to place the cursor at the top of the updateable list.
75  
76 =head2 C<< ->output_permanent >>
77  
78 $o->output_permanent("Frobnicated 3 items for job 2");
79 $o->output_list("Frobnicating 9 items for job 1",
80 "Frobnicating 2 items for job 3",
81 );
82 $o->output_permanent("Frobnicated 3 items for job 2");
83  
84 Outputs items that should go on the permanent record. It is expected to
85 output the (remaining) list of ongoing jobs after that.
86  
87 =head2 C<< ->output_list @items >>
88  
89 $o->output_list("Frobnicating 9 items for job 1",
90 "Frobnicating 2 items for job 3",
91 );
92  
93 Outputs items that can be updated later, as long as no intervening output
94 (like from C<print>, C<say> or C<warn>) has happened. If you want to output
95 lines that should not be overwritten later, see C<</->output_permanent>>
96  
97 =head2 C<< ->fresh_output >>
98  
99 $o->fresh_output();
100  
101 Helper subroutine to make all items from the last output list remain as is.
102  
103 For compatibility between output to a terminal and output without a terminal,
104 you should use C<< ->output_permanent >> for things that should be permanent
105 instead.
106  
107 =cut
108  
109 3 1;
« List/Role.pm ↑ Summary