File Coverage

blib/lib/Sub/Pipe.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             package Sub::Pipe;
2 2     2   25160 use warnings;
  2         6  
  2         60  
3 2     2   12 use strict;
  2         3  
  2         154  
4             our $VERSION = sprintf "%d.%02d", q$Revision: 0.3 $ =~ /(\d+)/g;
5 2     2   13 use base 'Exporter';
  2         8  
  2         316  
6             our @EXPORT = qw/joint/;
7              
8 2     2   4001 use overload '|' => sub { $_[0]->( $_[1] ) };
  2     2   2440  
  2         21  
  2         55  
9              
10 2     2 1 497 sub joint(&) { bless $_[0], __PACKAGE__ };
11              
12             if ( $0 eq __FILE__ ) {
13             local $\ = "\n";
14             my $uri = joint {
15             require URI::Escape;
16             URI::Escape::uri_escape_utf8(shift);
17             };
18             my $html = joint {
19             my $str = shift;
20             $str =~ s{([&<>"])}{
21             '&' . { qw/& amp < lt > gt " quot/ }->{$1} . ';' ;
22             }msgex;
23             $str;
24             };
25             my $html_line_break = joint {
26             local $_ = $_[0];
27             s{\r*\n}{
}g;
28             $_;
29             };
30             my $replace = sub {
31             my ( $regexp, $replace ) = @_;
32             joint {
33             my $str = shift;
34             $str =~ s{$regexp}{$replace}g;
35             $str;
36             }
37             };
38             print "dankogai" | joint { uc shift };
39             print "
" | $html; 
40             print "Perl & Me" | $uri;
41             print "PHP" | $replace->( 'HP', 'erl' );
42             print "Rock\nRoll" | $html_line_break | $uri;
43             }
44              
45             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
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<< >>
80              
81             Dan Kogai, C<< >>
82              
83             =head1 BUGS
84              
85             Please report any bugs or feature requests to C, or through
86             the web interface at L. 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
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 ACKNOWLEDGEMENTS
119              
120             L
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