| 1 | package Sub::Pipe; | ||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | our $VERSION = sprintf "%d.%02d", q$Revision: 0.3 $ =~ /(\d+)/g; | |||||||||
| 5 | 3 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | our @EXPORT = qw/joint/; | |||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use overload '|' => sub { $_[0]->( $_[1] ) }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | sub joint(&) { bless $_[0], __PACKAGE__ }; | ||||||||
|
Subroutine
joint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | ▶ | if ( $0 eq __FILE__ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 0 | local $\ = "\n"; | |||||||||
| 14 | 0 | ▶ | my $uri = joint { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 15 | 0 | require URI::Escape; | |||||||||
| 16 | 0 | URI::Escape::uri_escape_utf8(shift); | |||||||||
| 17 | 0 | }; | |||||||||
| 18 | 0 | ▶ | my $html = joint { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 19 | 0 | my $str = shift; | |||||||||
| 20 | 0 | $str =~ s{([&<>"])}{ | |||||||||
| 21 | 0 | '&' . { qw/& amp < lt > gt " quot/ }->{$1} . ';' ; | |||||||||
| 22 | }msgex; | ||||||||||
| 23 | 0 | $str; | |||||||||
| 24 | 0 | }; | |||||||||
| 25 | 0 | ▶ | my $html_line_break = joint { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 26 | 0 | local $_ = $_[0]; | |||||||||
| 27 | 0 | s{\r*\n}{<br/>}g; | |||||||||
| 28 | 0 | $_; | |||||||||
| 29 | 0 | }; | |||||||||
| 30 | 0 | ▶ | my $replace = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 31 | 0 | my ( $regexp, $replace ) = @_; | |||||||||
| 32 | 0 | ▶ | joint { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 33 | 0 | my $str = shift; | |||||||||
| 34 | 0 | $str =~ s{$regexp}{$replace}g; | |||||||||
| 35 | 0 | $str; | |||||||||
| 36 | } | ||||||||||
| 37 | 0 | }; | |||||||||
| 38 | 0 | ▶ | print "dankogai" | joint { uc shift }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 39 | 0 | print "<pre>" | $html; | |||||||||
| 40 | 0 | print "Perl & Me" | $uri; | |||||||||
| 41 | 0 | print "PHP" | $replace->( 'HP', 'erl' ); | |||||||||
| 42 | 0 | print "Rock\nRoll" | $html_line_break | $uri; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 3 | 1; # End of Sub::Pipe | |||||||||
| 46 | |||||||||||
| 47 | =head1 NAME | ||||||||||
| 48 | |||||||||||
| 49 | Sub::Pipe - chain subs with | (pipe) | ||||||||||
| 50 | |||||||||||
| 51 | =head1 VERSION | ||||||||||
| 52 | |||||||||||
| 53 | $Id: Pipe.pm,v 0.1 2009/05/22 06:36:59 dankogai Exp dankogai $ | ||||||||||
| 54 | |||||||||||
| 55 | =head1 SYNOPSIS | ||||||||||
| 56 | |||||||||||
| 57 | Quick summary of what the module does. | ||||||||||
| 58 | |||||||||||
| 59 | Perhaps a little code snippet. | ||||||||||
| 60 | |||||||||||
| 61 | use Sub::Pipe; | ||||||||||
| 62 | print "dankogai" | joint { uc shift }; # DANKOGAI | ||||||||||
| 63 | |||||||||||
| 64 | =head1 EXPORT | ||||||||||
| 65 | |||||||||||
| 66 | C<joint> | ||||||||||
| 67 | |||||||||||
| 68 | =head1 FUNCTIONS | ||||||||||
| 69 | |||||||||||
| 70 | =head2 joint | ||||||||||
| 71 | |||||||||||
| 72 | joint { ... } | ||||||||||
| 73 | joint(\&sub) | ||||||||||
| 74 | |||||||||||
| 75 | Bless the subroutine to this package so that the overloaded C<|> works. | ||||||||||
| 76 | |||||||||||
| 77 | =head1 AUTHOR | ||||||||||
| 78 | |||||||||||
| 79 | FUJIWARA Shunichiro C<< <fujiwara at cpan.org> >> | ||||||||||
| 80 | |||||||||||
| 81 | Dan Kogai, C<< <dankogai at dan.co.jp> >> | ||||||||||
| 82 | |||||||||||
| 83 | =head1 BUGS | ||||||||||
| 84 | |||||||||||
| 85 | Please report any bugs or feature requests to C<bug-sub-pipe at rt.cpan.org>, or through | ||||||||||
| 86 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sub-Pipe>. I will be notified, and then you'll | ||||||||||
| 87 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 88 | |||||||||||
| 89 | =head1 SUPPORT | ||||||||||
| 90 | |||||||||||
| 91 | You can find documentation for this module with the perldoc command. | ||||||||||
| 92 | |||||||||||
| 93 | perldoc Sub::Pipe | ||||||||||
| 94 | |||||||||||
| 95 | |||||||||||
| 96 | You can also look for information at: | ||||||||||
| 97 | |||||||||||
| 98 | =over 4 | ||||||||||
| 99 | |||||||||||
| 100 | =item * RT: CPAN's request tracker | ||||||||||
| 101 | |||||||||||
| 102 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sub-Pipe> | ||||||||||
| 103 | |||||||||||
| 104 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 105 | |||||||||||
| 106 | L<http://annocpan.org/dist/Sub-Pipe> | ||||||||||
| 107 | |||||||||||
| 108 | =item * CPAN Ratings | ||||||||||
| 109 | |||||||||||
| 110 | L<http://cpanratings.perl.org/d/Sub-Pipe> | ||||||||||
| 111 | |||||||||||
| 112 | =item * Search CPAN | ||||||||||
| 113 | |||||||||||
| 114 | L<http://search.cpan.org/dist/Sub-Pipe/> | ||||||||||
| 115 | |||||||||||
| 116 | =back | ||||||||||
| 117 | |||||||||||
| 118 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 119 | |||||||||||
| 120 | L<http://d.hatena.ne.jp/sfujiwara/20090521/1242921474> | ||||||||||
| 121 | |||||||||||
| 122 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 123 | |||||||||||
| 124 | Copyright 2009 FUJIWARA Shunichiro, all rights reserved. | ||||||||||
| 125 | |||||||||||
| 126 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 127 | under the same terms as Perl itself. | ||||||||||
| 128 | |||||||||||
| 129 | =cut | ||||||||||