From 260a36fc18e2bc1fd5c0040b92621b528e01b6ff Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Tue, 1 Apr 2014 01:34:49 +0300 Subject: [PATCH] Improve code --- lib/Text/Homestuck.pm | 87 +++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/lib/Text/Homestuck.pm b/lib/Text/Homestuck.pm index 88354ed..ff123ca 100644 --- a/lib/Text/Homestuck.pm +++ b/lib/Text/Homestuck.pm @@ -7,73 +7,71 @@ use parent qw/Exporter/; our @EXPORT = qw/aradia tavros sollux karkat nepeta kanaya terezi vriska equius gamzee eridan feferi/; our $VERSION = '0.000_001'; +sub filter { + my ($name, $code) = @_; + no strict 'refs'; + *{$name} = sub (;$){ + local *__ANON__ = $name; + if ($_[0]) { + local $_ = $_[0]; + $code->(); + $_ + } else { + $code->(); + $_ + } + } +} -sub aradia (_) { - local $_ = $_[0]; +filter aradia => sub { y/A-Z/a-z/; y/,.?//d; s/o/0/g; - $_ -} +}; -sub tavros (_) { - local $_ = $_[0]; +filter tavros => sub { y/a-zA-Z.!?/A-Za-z,,,/; s/:\)/}:)/g; - $_ -} +}; -sub sollux (_) { - local $_ = $_[0]; +filter sollux => sub { y/A-Z/a-z/; y/s/2/; s/i/ii/g; s/to/two/g; s/\b(fuck|joke|kk|aa)\b/\U$1/g; - $_ -} +}; -sub karkat (_) { - local $_ = $_[0]; +filter karkat => sub { y/a-z/A-Z/; s/\bD:/D:B/; - $_ -} +}; -sub nepeta (_){ - local $_ = $_[0]; +filter nepeta => sub { y/A-Z/a-z/; s/ee/33/; $_ = ":33 < $_"; - $_ -} +}; -sub kanaya (_) { - local $_ = $_[0]; +filter kanaya => sub { y/,.!?'//d; s/\b(\w)/\u$1/g; - $_ -} +}; -sub terezi (_) { - local $_ = $_[0]; +filter terezi => sub { y/a-z/A-Z/; y/AIE/413/; s/(!|\?)/$1$1/g; s/:\]|:\)/>:]/g; - $_ -} +}; -sub vriska (_) { - local $_ = $_[0]; +filter vriska => sub { y/Bb/88/; s/:\)/::::\)/g; s/D:/D::::/g; - $_ -} +}; -sub equius (_){ - local $_ = $_[0]; +filter equius => sub { s/strong/STRONG/g; s/strength/STRONGNESS/g; s/x/%/ig; @@ -81,35 +79,28 @@ sub equius (_){ s/ool/001/ig; s/[?.!]$//; $_ = "D --> $_"; - $_ -} +}; -sub gamzee (_){ - local $_ = $_[0]; +filter gamzee => sub { y/[A-Z]/[a-z]/; s/([a-z])(.)/$1\u$2/g; s/:\)/:o\)/g; - $_ -} +}; -sub eridan (_){ - local $_ = $_[0]; +filter eridan => sub { y/',.?!//d; s/w/ww/g; s/v/vv/g; s/ing/in/g; s/want to/wanna/g; s/going to/gonna/g; - $_ -} +}; -sub feferi (_){ - local $_ = $_[0]; +filter feferi => sub { s/H/)(/g; s/E/-E/g; s/:\)/38)/g; - $_ -} +}; 1; __END__ -- 2.39.2