| 1 | package Text::Chomped; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 2 | 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<chomped> and C<chopped> which behave like C<chomp> and C<chop> 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 | ▶ | use vars qw/@ISA @EXPORT/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 63 | 2 | @ISA = qw/Exporter/; | |||||||||
| 64 | 2 | @EXPORT = qw/chomped chopped/; | |||||||||
| 65 | |||||||||||
| 66 | 7 | ▶ | sub _chomped { | ||||||||
|
Subroutine
_chomped: called CC=1 SCAR=0.0
| |||||||||||
| 67 | 7 | my $value = $_[0]; | |||||||||
| 68 | 7 | chomp $value; | |||||||||
| 69 | 7 | return $value; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 5 | ▶ | sub chomped ($) { | ||||||||
|
Subroutine
chomped: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 73 | 5 | my $value = $_[0]; | |||||||||
| 74 | 5 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 1 | my @result = map { _chomped $_ } @$value; | |||||||||
| 76 | 1 | ▶ | return wantarray ? @result : \@result; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | } | ||||||||||
| 78 | else { | ||||||||||
| 79 | 4 | return _chomped $value; | |||||||||
| 80 | } | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 4 | ▶ | sub _chopped { | ||||||||
|
Subroutine
_chopped: called CC=1 SCAR=0.0
| |||||||||||
| 84 | 4 | my $value = $_[0]; | |||||||||
| 85 | 4 | chop $value; | |||||||||
| 86 | 4 | return $value; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 2 | ▶ | sub chopped ($) { | ||||||||
|
Subroutine
chopped: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 90 | 2 | my $value = $_[0]; | |||||||||
| 91 | 2 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 1 | my @result = map { _chopped $_ } @$value; | |||||||||
| 93 | 1 | ▶ | return wantarray ? @result : \@result; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | } | ||||||||||
| 95 | else { | ||||||||||
| 96 | 1 | 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<< <rkrimen at cpan.org> >> | ||||||||||
| 121 | |||||||||||
| 122 | =head1 BUGS | ||||||||||
| 123 | |||||||||||
| 124 | Please report any bugs or feature requests to C<bug-text-chomped at rt.cpan.org>, or through | ||||||||||
| 125 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-Chomped>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-Chomped> | ||||||||||
| 145 | |||||||||||
| 146 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 147 | |||||||||||
| 148 | L<http://annocpan.org/dist/Text-Chomped> | ||||||||||
| 149 | |||||||||||
| 150 | =item * CPAN Ratings | ||||||||||
| 151 | |||||||||||
| 152 | L<http://cpanratings.perl.org/d/Text-Chomped> | ||||||||||
| 153 | |||||||||||
| 154 | =item * Search CPAN | ||||||||||
| 155 | |||||||||||
| 156 | L<http://search.cpan.org/dist/Text-Chomped/> | ||||||||||
| 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 | 2 | 'PACMAN'; # End of Text::Chomped | |||||||||