Created
May 21, 2009 12:57
-
-
Save fujiwara/115444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Filter; | |
use strict; | |
require Exporter; | |
our @ISA = qw/ Exporter /; | |
our @EXPORT_OK = qw/ html uri replace html_line_break /; | |
our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |
use overload | |
'|' => sub { | |
my ($self, @args) = @_; | |
$self->(@args); | |
}, | |
; | |
sub html() { | |
bless sub { | |
local $_ = $_[0]; | |
s{&}{&}g; | |
s{<}{<}g; | |
s{>}{>}g; | |
s{"}{"}g; | |
s{'}{'}g; | |
$_; | |
}, __PACKAGE__; | |
} | |
sub uri() { | |
use URI::Escape; | |
bless sub { | |
uri_escape_utf8($_[0]); | |
}, __PACKAGE__; | |
} | |
sub replace($$) { | |
my ($regexp, $replace) = @_; | |
bless sub { | |
local $_ = $_[0]; | |
s{$regexp}{$replace}g; | |
$_; | |
}, __PACKAGE__; | |
} | |
sub html_line_break() { | |
bless sub { | |
local $_ = $_[0]; | |
s{\r*\n}{<br/>}g; | |
$_; | |
}, __PACKAGE__; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment