UI/History.pm

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