Permalink
Browse files

Add guard for the case Filter::tee is not available.

  • Loading branch information...
yak1ex committed Nov 13, 2012
1 parent ed4594b commit 898f154f4805605718761c2b4165e13ada07ac80
Showing with 18 additions and 10 deletions.
  1. +14 −10 lib/filtered.pm
  2. +4 −0 t/debug.pl
View
@@ -121,17 +121,21 @@ sub filtered::hook::INC
$_ .= ' '.$self->{_WITH};
}
if(exists $ENV{FILTERED_ROOT}) {
- my $asfile;
- if(defined($self->{_AS})) {
- $asfile = $self->{_AS};
- $asfile =~ s@::@/@g;
- $asfile .= '.pm';
+ if(eval { require Filter::tee; }) {
+ my $asfile;
+ if(defined($self->{_AS})) {
+ $asfile = $self->{_AS};
+ $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 {
- $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";
$_[1] = 0;
@@ -274,7 +278,7 @@ Rest of the options are passed to C<import> of filtered module.
=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>.
=head1 CAVEATS
View
@@ -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::Exception;

0 comments on commit 898f154

Please sign in to comment.