Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Created May 21, 2009 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fujiwara/115444 to your computer and use it in GitHub Desktop.
Save fujiwara/115444 to your computer and use it in GitHub Desktop.
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{<}{&lt;}g;
s{>}{&gt;}g;
s{"}{&quot;}g;
s{'}{&#39}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