| 1 | package Acme::Hidek::Congrats; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | my $package = __PACKAGE__; | ||
| 6 | |||
| 7 | my $tie = "WE LOVE HIDEK!\n\n"; | ||
| 8 | |||
| 9 | my @messages = ( | ||
| 10 | 'Happy birthday,', | ||
| 11 | 'Happy 40th birthday,', | ||
| 12 | 'Congrats', | ||
| 13 | 'Congrats on your birthday,', | ||
| 14 | 'Congrats on your 40th birthday,', | ||
| 15 | 'Congratulations,', | ||
| 16 | 'Congratulations on your birthday,', | ||
| 17 | 'Congratulations on your 40th birthday,', | ||
| 18 | 'Hearty congratulations,', | ||
| 19 | 'Hearty congratulations on your birthday,', | ||
| 20 | 'Hearty congratulations on your 40th birthday,', | ||
| 21 | 'Heartiest congratulations,', | ||
| 22 | 'Heartiest congratulations on your birthday,', | ||
| 23 | 'Heartiest congratulations on your 40th birthday,', | ||
| 24 | ); | ||
| 25 | |||
| 26 | sub whiten { | ||
| 27 | local $_ = unpack "b*", pop; | ||
| 28 | s/0/"$messages[rand @messages] hidek!\n\n"/ge; | ||
| 29 | s/1/"$messages[rand @messages] Hidek!\n\n"/ge; | ||
| 30 | $tie.$_; | ||
| 31 | } | ||
| 32 | sub brighten { | ||
| 33 | local $_ = pop; | ||
| 34 | s/^\Q$tie\E//xmsg; | ||
| 35 | s/\d//g; | ||
| 36 | s/\b hidek \b/0/xmsg; | ||
| 37 | s/\b Hidek \b/1/xmsg; | ||
| 38 | s/[^01]//g; | ||
| 39 | pack "b*", $_; | ||
| 40 | } | ||
| 41 | |||
| 42 | sub dress { $_[0] =~ /^$tie/ } | ||
| 43 | |||
| 44 | open my $in, '<', $0 or print "Can't rebleach '$0'\n" and exit; | ||
| 45 | |||
| 46 | (my $shirt = join "", <$in>) =~ s/.* ^ \s* use \s+ \Q$package\E \s* ; \n //xms; | ||
| 47 | |||
| 48 | do { eval brighten $shirt; $@ && die; exit } unless not dress $shirt; | ||
| 49 | |||
| 50 | open my $out, '>', "${0}c" or print "Cannot bleach '${0}c'\n" and exit; | ||
| 51 | print {$out} "use $package;\n", whiten $shirt; |