line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Handle::Filter::Output::Timestamp; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: prepend filehandle output with a timestamp |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
19693
|
use 5.008; |
|
1
|
|
|
|
|
2
|
|
6
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
7
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
8
|
1
|
|
|
1
|
|
2
|
use base 'Tie::Handle::Filter'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
357
|
|
9
|
1
|
|
|
1
|
|
6
|
use POSIX 'strftime'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.009'; # TRIAL |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
13
|
|
|
|
|
|
|
#pod |
14
|
|
|
|
|
|
|
#pod use Tie::Handle::Filter::Output::Timestamp; |
15
|
|
|
|
|
|
|
#pod tie *STDOUT, 'Tie::Handle::Filter::Output::Timestamp', *STDOUT; |
16
|
|
|
|
|
|
|
#pod |
17
|
|
|
|
|
|
|
#pod print "Everything I print will be prepended with a timestamp.\n"; |
18
|
|
|
|
|
|
|
#pod print <<'END_OUTPUT'; |
19
|
|
|
|
|
|
|
#pod The first line of a multi-line string will be prepended. |
20
|
|
|
|
|
|
|
#pod Subsequent lines will not. |
21
|
|
|
|
|
|
|
#pod END_OUTPUT |
22
|
|
|
|
|
|
|
#pod |
23
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
24
|
|
|
|
|
|
|
#pod |
25
|
|
|
|
|
|
|
#pod This class may be used with Perl's L function to |
26
|
|
|
|
|
|
|
#pod prepend all output with a timestamp, optionally formatted according to |
27
|
|
|
|
|
|
|
#pod the L|POSIX/strftime> function. Only the beginning of |
28
|
|
|
|
|
|
|
#pod strings given to L|perlfunc/print>, |
29
|
|
|
|
|
|
|
#pod L|perlfunc/printf>, L|perlfunc/syswrite>, and |
30
|
|
|
|
|
|
|
#pod L|perlfunc/say> (in Perl > v5.10) get timestamps. If you want |
31
|
|
|
|
|
|
|
#pod I line prefixed, use |
32
|
|
|
|
|
|
|
#pod L|Tie::Handle::Filter::Output::Timestamp::EveryLine>, |
33
|
|
|
|
|
|
|
#pod |
34
|
|
|
|
|
|
|
#pod =head1 BUGS AND LIMITATIONS |
35
|
|
|
|
|
|
|
#pod |
36
|
|
|
|
|
|
|
#pod Because the date and time format is specified using |
37
|
|
|
|
|
|
|
#pod L|POSIX/strftime>, portable code should restrict itself to |
38
|
|
|
|
|
|
|
#pod formats using ANSI C89 specifiers. |
39
|
|
|
|
|
|
|
#pod |
40
|
|
|
|
|
|
|
#pod =method TIEHANDLE |
41
|
|
|
|
|
|
|
#pod |
42
|
|
|
|
|
|
|
#pod Invoked by the command |
43
|
|
|
|
|
|
|
#pod C. |
44
|
|
|
|
|
|
|
#pod You may also specify a L|POSIX/strftime> string as an |
45
|
|
|
|
|
|
|
#pod additional parameter to format the timestamp; by default the format is |
46
|
|
|
|
|
|
|
#pod C<%x %X >, which is the local representation of the date and time |
47
|
|
|
|
|
|
|
#pod followed by a space. |
48
|
|
|
|
|
|
|
#pod |
49
|
|
|
|
|
|
|
#pod =cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub TIEHANDLE { |
52
|
1
|
|
|
1
|
|
195
|
my ( $class, $handle_glob, $format ) = @_; |
53
|
1
|
|
50
|
|
|
6
|
$format ||= '%x %X '; |
54
|
|
|
|
|
|
|
return $class->SUPER::TIEHANDLE( $handle_glob, |
55
|
1
|
|
|
2
|
|
13
|
sub { ( strftime( $format, localtime ), @_ ) } ); |
|
2
|
|
|
|
|
6
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |