Skip to content

Commit

Permalink
Add guard for the case Filter::tee is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
yak1ex committed Nov 13, 2012
1 parent ed4594b commit 898f154
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/filtered.pm
Expand Up @@ -121,17 +121,21 @@ sub filtered::hook::INC
$_ .= ' '.$self->{_WITH}; $_ .= ' '.$self->{_WITH};
} }
if(exists $ENV{FILTERED_ROOT}) { if(exists $ENV{FILTERED_ROOT}) {
my $asfile; if(eval { require Filter::tee; }) {
if(defined($self->{_AS})) { my $asfile;
$asfile = $self->{_AS}; if(defined($self->{_AS})) {
$asfile =~ s@::@/@g; $asfile = $self->{_AS};
$asfile .= '.pm'; $asfile =~ s@::@/@g;
$asfile .= '.pm';
} else {
$asfile = $filename;
}
my $dir = dirname($ENV{FILTERED_ROOT}.'/'.$asfile);
File::Path::make_path($dir) if ! -d $dir;
$_ .= "; use Filter::tee '".$ENV{FILTERED_ROOT}.'/'.$asfile."'";
} else { } else {
$asfile = $filename; warn 'Ignore environment variable FILTERED_ROOT because Filter::tee is not available';
} }
my $dir = dirname($ENV{FILTERED_ROOT}.'/'.$asfile);
File::Path::make_path($dir) if ! -d $dir;
$_ .= "; use Filter::tee '".$ENV{FILTERED_ROOT}.'/'.$asfile."'";
} }
$_ .= ";\n"; $_ .= ";\n";
$_[1] = 0; $_[1] = 0;
Expand Down Expand Up @@ -274,7 +278,7 @@ Rest of the options are passed to C<import> of filtered module.
=head1 DEBUG =head1 DEBUG
If environment variable C<FILTERED_ROOT> is specified, filtered results are stored under the directory. If L<Filter::tee> is available and environment variable C<FILTERED_ROOT> is specified, filtered results are stored under the directory.
Assuming the filtered module name is C<Filtered::Target>, the filtered result is stored as C<FILTERED_ROOT/Filtered/Target.pm>. Assuming the filtered module name is C<Filtered::Target>, the filtered result is stored as C<FILTERED_ROOT/Filtered/Target.pm>.
=head1 CAVEATS =head1 CAVEATS
Expand Down
4 changes: 4 additions & 0 deletions t/debug.pl
@@ -1,3 +1,7 @@
BEGIN {
require Test::More;
Test::More::plan(skip_all => 'Filter::tee is not available') unless eval { require Filter::tee; };
}
use Test::More tests => 10; use Test::More tests => 10;
use Test::Exception; use Test::Exception;


Expand Down

0 comments on commit 898f154

Please sign in to comment.