line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Chomped; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
157048
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
106
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Text::Chomped - A chomp and chop that will return the chomped and chopped |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.02 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Old way |
21
|
|
|
|
|
|
|
sub sentence { |
22
|
|
|
|
|
|
|
my $value = <<_END_ |
23
|
|
|
|
|
|
|
A quick brown fox jumped over the lazy dog |
24
|
|
|
|
|
|
|
_END_ |
25
|
|
|
|
|
|
|
chomp $value; |
26
|
|
|
|
|
|
|
return $value; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# New way |
30
|
|
|
|
|
|
|
use Text::Chomped; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub sentence { chomped <<_END_ } |
33
|
|
|
|
|
|
|
A quick brown fox jumped over the lazy dog |
34
|
|
|
|
|
|
|
_END_ |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Chomp a list (have to use [], sorry) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my @got = chomped [ "A\n", "b", "c\n", ... ] |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# ... or ... |
41
|
|
|
|
|
|
|
my $got = chomped [ "A\n", "b", "c\n", ... ] |
42
|
|
|
|
|
|
|
$got->[0] # A |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTON |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Text::Chomped will export C and C which behave like C and C except return the cho[mp]ped value rather than |
47
|
|
|
|
|
|
|
what was cho[mp]ped off (the character) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Unfortunately subroutine prototyping in Perl cannot ape the builtin chomp/chop prototype, so you'll have to pass in an ARRAY reference if you want to |
50
|
|
|
|
|
|
|
chomp/chop a list |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Another consequence of the above, is that we can't use C<$_> without making the interface annoying, so you can't do: |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
map { chomped } "A\n", "b", "c\n" |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
You have to do: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
map { chomped $_ } "A\n", "b", "c\n" |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
2
|
|
10
|
use vars qw/@ISA @EXPORT/; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
797
|
|
63
|
|
|
|
|
|
|
@ISA = qw/Exporter/; |
64
|
|
|
|
|
|
|
@EXPORT = qw/chomped chopped/; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _chomped { |
67
|
7
|
|
|
7
|
|
12
|
my $value = $_[0]; |
68
|
7
|
|
|
|
|
13
|
chomp $value; |
69
|
7
|
|
|
|
|
26
|
return $value; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub chomped ($) { |
73
|
5
|
|
|
5
|
0
|
94
|
my $value = $_[0]; |
74
|
5
|
100
|
|
|
|
15
|
if ( ref $value eq 'ARRAY' ) { |
75
|
1
|
|
|
|
|
3
|
my @result = map { _chomped $_ } @$value; |
|
3
|
|
|
|
|
5
|
|
76
|
1
|
50
|
|
|
|
11
|
return wantarray ? @result : \@result; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
4
|
|
|
|
|
8
|
return _chomped $value; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _chopped { |
84
|
4
|
|
|
4
|
|
7
|
my $value = $_[0]; |
85
|
4
|
|
|
|
|
8
|
chop $value; |
86
|
4
|
|
|
|
|
12
|
return $value; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub chopped ($) { |
90
|
2
|
|
|
2
|
0
|
7
|
my $value = $_[0]; |
91
|
2
|
100
|
|
|
|
10
|
if ( ref $value eq 'ARRAY' ) { |
92
|
1
|
|
|
|
|
3
|
my @result = map { _chopped $_ } @$value; |
|
3
|
|
|
|
|
6
|
|
93
|
1
|
50
|
|
|
|
8
|
return wantarray ? @result : \@result; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
1
|
|
|
|
|
4
|
return _chopped $value; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Y\ /Y |
103
|
|
|
|
|
|
|
| \ _ / | |
104
|
|
|
|
|
|
|
_____ | =(_)= | |
105
|
|
|
|
|
|
|
,-~" "~-. ,-~\/^ ^\/~-. |
106
|
|
|
|
|
|
|
,^ ___ ___ ^. ,^ ___ ___ ^. |
107
|
|
|
|
|
|
|
/ .^ ^. .^ ^. \ / .^ ^. .^ ^. \ |
108
|
|
|
|
|
|
|
Y l O! l O! Y Y lo ! lo ! Y |
109
|
|
|
|
|
|
|
l_ `.___.' `.___.' _[ l_ `.___.' `.___.' _[ |
110
|
|
|
|
|
|
|
l^~"-------------"~^I l^~"-------------"~^I |
111
|
|
|
|
|
|
|
!\, ,/! ! ! |
112
|
|
|
|
|
|
|
\ ~-.,_______,.-~ / \ / |
113
|
|
|
|
|
|
|
^. .^ ^. .^ -Row |
114
|
|
|
|
|
|
|
"-.._____.,-" "-.._____.,-" |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
->Mr&MrsPacman<- |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Robert Krimen, C<< >> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 BUGS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
125
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
126
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 SUPPORT |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
perldoc Text::Chomped |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
You can also look for information at: |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=over 4 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * CPAN Ratings |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * Search CPAN |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Copyright 2009 Robert Krimen, all rights reserved. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
169
|
|
|
|
|
|
|
under the same terms as Perl itself. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
'PACMAN'; # End of Text::Chomped |