fix bug where first event isn't passed to filter during collect w/out inside
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / MaybeDebug.pm
CommitLineData
ee1a4266 1package HTML::Zoom::MaybeDebug;
2
3use strictures 1;
4
5sub import { }
6
7if (my $level = $ENV{'HTML_ZOOM_DEBUG'}) {
8 foreach my $mod (qw(Smart::Comments Data::Dumper::Concise JSON)) {
9 (my $file_stem = $mod) =~ s/::/\//g;
10 die "HTML_ZOOM_DEBUG env var set to ${level} - this requires the ${mod}\n"
11 ."module but it failed to load with error:\n$@"
12 unless eval { require "${file_stem}.pm"; 1 };
13 }
14 my @smartness = map '#'x$_, 3 .. $level+2;
15 no warnings 'redefine';
16 *import = sub { Smart::Comments->import(@smartness) };
17 my $j = JSON->new->space_after;
18 my $d = \&Data::Dumper::Concise::Dumper;
19 *Smart::Comments::Dumper = sub {
20 my $r;
21 unless (eval { $r = $j->encode($_[0]); 1 }) {
22 $r = $d->($_[0]);
23 }
24 $r;
25 };
26}
27
281;