lib/Term/UI/History.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 4 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 93.8% 61 / 65 SCAR 16.1
CC
5
Cov
98%
history
4.0
BEGIN
2.0
BEGIN
1.0
CRAP 5.0
« blib/lib/Term/UI/History.pm ↑ Summary
1 package Term::UI::History;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use vars qw[$VERSION];
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use base 'Log::Message::Simple';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 $VERSION = '0.46';
9  
10 =pod
11  
12 =head1 NAME
13  
14 Term::UI::History - history function
15  
16 =head1 SYNOPSIS
17  
18 use Term::UI::History qw[history];
19  
20 history("Some message");
21  
22 ### retrieve the history in printable form
23 $hist = Term::UI::History->history_as_string;
24  
25 ### redirect output
26 local $Term::UI::History::HISTORY_FH = \*STDERR;
27  
28 =head1 DESCRIPTION
29  
30 This module provides the C<history> function for C<Term::UI>,
31 printing and saving all the C<UI> interaction.
32  
33 Refer to the C<Term::UI> manpage for details on usage from
34 C<Term::UI>.
35  
36 This module subclasses C<Log::Message::Simple>. Refer to its
37 manpage for additional functionality available via this package.
38  
39 =head1 FUNCTIONS
40  
41 =head2 history("message string" [,VERBOSE])
42  
43 Records a message on the stack, and prints it to C<STDOUT>
44 (or actually C<$HISTORY_FH>, see the C<GLOBAL VARIABLES> section
45 below), if the C<VERBOSE> option is true.
46  
47 The C<VERBOSE> option defaults to true.
48  
49 =cut
50  
51 BEGIN {
52 3 ▶ use Log::Message private => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 3 ▶ use vars qw[ @EXPORT $HISTORY_FH ];
Subroutine BEGIN: called CC=1 SCAR=0.0
55 3 ▶ @EXPORT = qw[ history ];
Subroutine BEGIN: called CC=2 SCAR=6.9
56 3 my $log = new Log::Message;
57 3 $HISTORY_FH = \*STDOUT;
58  
59 3 for my $func ( @EXPORT ) {
60 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 2 ▶ *$func = sub { my $msg = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
63 2 $log->store(
64 message => $msg,
65 tag => uc $func,
66 level => $func,
67 extra => [@_]
68 );
69 3 };
70 }
71  
72 sub history_as_string {
73 3 ▶ my $class = shift;
Subroutine history_as_string: called CC=1 SCAR=0.0
Pod undocumented
74  
75 3 return join $/, map { $_->message } __PACKAGE__->stack;
76 }
77 }
78  
79  
80 {
81 package # hide this from PAUSE
82 Log::Message::Handlers;
83  
84 sub history {
85 2 ▶ my $self = shift;
Subroutine history: called CC=4 SCAR=13.9
Pod undocumented
86 2 my $verbose = shift;
87 2 ▶ $verbose = 1 unless defined $verbose; # default to true
Branch: 1 branch
BranchTrueFalseTotal
unless defined $verbose 1 1 2
88  
89 ### so you don't want us to print the msg? ###
90 2 ▶ return if defined $verbose && $verbose == 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $verbose and $verbose == 0 1 1 2
Condition66%2/3
defined $verbose and $verbose == 0
!ll&&!rl&&r
011
MC/DC50%1/2
defined $verbose and $verbose == 0
defined $verbose $verbose == 0
Truth table66%2/3
A and B
A= defined $verboseB= $verbose == 0
ABresult
0X0
100
111
91  
92 1 local $| = 1;
93 1 my $old_fh = select $Term::UI::History::HISTORY_FH;
94  
95 1 print $self->message . "\n";
96 1 select $old_fh;
97  
98 1 return;
99 }
100 }
101  
102  
103 =head1 GLOBAL VARIABLES
104  
105 =over 4
106  
107 =item $HISTORY_FH
108  
109 This is the filehandle all the messages sent to C<history()> are being
110 printed. This defaults to C<*STDOUT>.
111  
112 =back
113  
114 =head1 See Also
115  
116 C<Log::Message::Simple>, C<Term::UI>
117  
118 =head1 AUTHOR
119  
120 This module by
121 Jos Boumans E<lt>kane@cpan.orgE<gt>.
122  
123 =head1 COPYRIGHT
124  
125 This module is
126 copyright (c) 2005 Jos Boumans E<lt>kane@cpan.orgE<gt>.
127 All rights reserved.
128  
129 This library is free software;
130 you may redistribute and/or modify it under the same
131 terms as Perl itself.
132  
133 =cut
134  
135 3 1;
136  
137 # Local variables:
138 # c-indentation-style: bsd
139 # c-basic-offset: 4
140 # indent-tabs-mode: nil
141 # End:
142 # vim: expandtab shiftwidth=4:
« blib/lib/Term/UI/History.pm ↑ Summary