package OpenXPKI::Debug; use Filter::Util::Call; sub filter { # [...] $_ = << "XEOF"; { my \$subroutine = (caller(0))[3]; my \$line = __LINE__; eval q{ OpenXPKI::Debug::debug({ MESSAGE => sub { $msg }, LINE => \$line, SUBROUTINE => \$subroutine, LEVEL => q{$level}, COLOR => q{$color} }); }; if (\$\@) { print STDERR 'Invalid DEBUG statement: ' . q{$msg} . ': ' . \$\@ . "\n"; } } XEOF s/\n/ /g; $_ .= "\n"; # [...] }
Not that source filters as such were not evil enough, we wanted to ensure that they don't do any more damage if someone makes syntax errors in his debug comments. This is what resulted after about an afternoon of »My brain hurts!«. If you can understand how it works and why we did it in exactly this way, you have my respect and may call yourself a real perl hacker. If you don't, you might be interested in reading the version with the 20-odd line comment startwing with »HERE BE DRAGONS«.