From 898f154f4805605718761c2b4165e13ada07ac80 Mon Sep 17 00:00:00 2001 From: Yasutaka ATARASHI Date: Tue, 13 Nov 2012 23:56:36 +0900 Subject: [PATCH] Add guard for the case Filter::tee is not available. --- lib/filtered.pm | 24 ++++++++++++++---------- t/debug.pl | 4 ++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/filtered.pm b/lib/filtered.pm index e40a142..2189acb 100644 --- a/lib/filtered.pm +++ b/lib/filtered.pm @@ -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 of filtered module. =head1 DEBUG -If environment variable C is specified, filtered results are stored under the directory. +If L is available and environment variable C is specified, filtered results are stored under the directory. Assuming the filtered module name is C, the filtered result is stored as C. =head1 CAVEATS diff --git a/t/debug.pl b/t/debug.pl index 21187fb..ecbe8e2 100644 --- a/t/debug.pl +++ b/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::Exception;