| Category: | Miscellaneous |
| Author/Contact Info | /msg Dylan |
| Description: | Drugs is a perl module that makes existing perl scripts more interesting.
I'd be interested if anyone else finds this funny...
"This is your script, this is your script on drugs" <g>
Update: Modifed to be less C-like (Thanks, Aristotle). Update: Fixed sprintf thing. |
package IO::Drug;
use strict;
use Tie::Handle;
our @ISA = qw(Tie::Handle);
sub PRINT {
my $self = shift;
print $self (map lsd($_), @_);
}
sub PRINTF {
my ($self, $fmt) = splice @_, 0, 2;
print $self lsd(sprintf $fmt, @_);
}
sub TIEHANDLE {
my ($class, $handle) = @_;
bless $handle, $class;
}
sub lsd {
my @colors = qw(red green yellow blue cyan magenta);
push @colors, map "bold $_", @colors;
# map chr, unpack "c*" is faster than split //
return
join '', map colored(chr $_, $colors[rand @colors]),
unpack "c*", $_[0];
}
package Drugs;
use strict;
use Carp;
use Filter::Util::Call;
use Term::ANSIColor;
sub import { filter_add bless {} }
sub filter {
my ($self) = @_ ;
my $status = filter_read();
intoxicate_linenums() if $status;
return $status;
}
sub intoxicate_linenums {
return join "\n", map {
my $rnd = 1 + int rand 1000;
my ($prog) = $0 =~ /([^\/]+)\z/;
if(rand 2) {
my @files =
grep {$_ ne $prog and not -d $_}
glob('*'), glob('**/*');
my $file = $files[rand @files] || 'Fat Albert';
qq(#line $rnd "$file"\n$_);
}
else {
"#line $rnd $prog\n$_";
}
} split /\n/;
}
$SIG{__WARN__} = sub { print STDERR @_ };
$SIG{__DIE__} = sub { print STDERR @_ ; exit };
open my $out, ">&STDOUT" or die "Can't dup!";
tie *STDOUT, "IO::Drug", $out;
open my $err, ">&STDERR" or die "Can't dup!";
tie *STDERR, "IO::Drug", $err;
1;
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use Drugs;
by Aristotle (Chancellor) on Sep 01, 2002 at 19:30 UTC | |
by Dylan (Monk) on Sep 01, 2002 at 22:23 UTC | |
by Aristotle (Chancellor) on Sep 02, 2002 at 00:28 UTC | |
by Aristotle (Chancellor) on Sep 07, 2002 at 23:03 UTC | |
by Dylan (Monk) on Sep 08, 2002 at 20:43 UTC | |
|
Re: use Drugs;
by Dylan (Monk) on Aug 31, 2002 at 05:30 UTC | |
|
Re: use Drugs;
by Dylan (Monk) on Aug 30, 2002 at 17:04 UTC |