line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Backtick::AutoChomp; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
49386
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
74
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
5
|
2
|
|
|
2
|
|
4500
|
use Filter::Simple; |
|
2
|
|
|
|
|
81716
|
|
|
2
|
|
|
|
|
17
|
|
6
|
2
|
|
|
2
|
|
2214
|
use PPI; |
|
2
|
|
|
|
|
386472
|
|
|
2
|
|
|
|
|
477
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
FILTER { |
9
|
|
|
|
|
|
|
my $doc = PPI::Document->new(\$_); |
10
|
|
|
|
|
|
|
$_->set_content(sprintf 'do{local $_=%s;chomp;$_}', $_->content) |
11
|
|
|
|
|
|
|
for @{ $doc->find( sub { |
12
|
|
|
|
|
|
|
$_[1]->isa('PPI::Token::QuoteLike::Backtick') |
13
|
|
|
|
|
|
|
or |
14
|
|
|
|
|
|
|
$_[1]->isa('PPI::Token::QuoteLike::Command') |
15
|
|
|
|
|
|
|
} ) || [] |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
$_ = $doc->content; |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
1; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=pod |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Backtick::AutoChomp - auto-chomp() result of backtick(``) and qx// |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 VERSION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Version 0.02 |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Automatically C result of a backtick (``) or qx// command. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$s = `echo blah` . 'stuff'; |
37
|
|
|
|
|
|
|
print $s; # blah\nstuff |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use Backtick::AutoChomp; |
40
|
|
|
|
|
|
|
$s = `echo blah` . 'stuff'; |
41
|
|
|
|
|
|
|
print $s; # blahstuff |
42
|
|
|
|
|
|
|
no Backtick::AutoChomp; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
In bash, the shell will automatically chomp the result of a backtick call. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
s=`whoami` # me |
49
|
|
|
|
|
|
|
echo =$s= # =me= |
50
|
|
|
|
|
|
|
echo =`whoami`= # =me= |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
In perl, we mustB<**> do: |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$s = `whoami`; |
55
|
|
|
|
|
|
|
chomp($s); |
56
|
|
|
|
|
|
|
print "=$s="; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
The goal of this module is for this to DWIM: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
print "=".`whoami`."="; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Another case where this is potentially useful: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use Backtick::AutoChomp; |
65
|
|
|
|
|
|
|
printf "me(%s), host(%s), kernel(%s), date(%s)\n", |
66
|
|
|
|
|
|
|
`whoami`, |
67
|
|
|
|
|
|
|
`hostname`, |
68
|
|
|
|
|
|
|
`uname -r`, |
69
|
|
|
|
|
|
|
`date`, |
70
|
|
|
|
|
|
|
; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
B<**> Yes, there are pure-perl ways to do I, I, etc. But keep in mind programs that don't have equivalents ... and also, especially for temp/quick-n-dirty scripts, the convenience factor :) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Note that this is implemented as a source filter. It replaces a backtick or qx statement with a C statement. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SEE ALSO |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
L, L |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 AUTHOR |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
David Westbrook (CPAN: davidrw), C<< >> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 BUGS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
87
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
88
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SUPPORT |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
perldoc Backtick::AutoChomp |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
You can also look for information at: |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over 4 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * CPAN Ratings |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * Search CPAN |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=back |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Copyright 2008 David Westbrook, all rights reserved. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
123
|
|
|
|
|
|
|
under the same terms as Perl itself. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|