FilterUtilCall.pm (PDL-2.075) | : | FilterUtilCall.pm (PDL-2.076) | ||
---|---|---|---|---|
# This original Filter::Util::Call-based | # This original Filter::Util::Call-based | |||
# PDL::NiceSlice engine. | # PDL::NiceSlice engine. | |||
# | # | |||
use strict; | use strict; | |||
use warnings; | use warnings; | |||
use Filter::Util::Call; | use Filter::Util::Call; | |||
############################## | { | |||
# If you mess with the import filter, please also change the pdlpp importer | no warnings 'redefine'; | |||
# just above this comment! They both do similar things, but one to an eval stri | sub PDL::NiceSlice::FilterUtilCall::make_filter { | |||
ng | my ($class,$file,$offset) = @_; | |||
# and one to an import file. | my $terminator = terminator_regexp($class); | |||
# --CED 5-Nov-2007 | sub { | |||
# | my ($status, $off, $end); | |||
my $count = 0; | ||||
my $data = ""; | ||||
while ($status = filter_read()) { | ||||
return $status if $status < 0; | ||||
if (defined($terminator) && m/$terminator/) { | ||||
$off=1; | ||||
last; | ||||
} | ||||
if (m/^\s*(__END__|__DATA__)\s*$/) { | ||||
$end=$1; $off = 1; | ||||
last; | ||||
} | ||||
$data .= $_; | ||||
$count++; | ||||
$_ = ""; | ||||
} | ||||
$_ = $data; | ||||
$_ = findslice $_ unless $status < 0; # the actual filter | ||||
$_ .= "no $class;\n" if $off; | ||||
$_ .= "$end\n" if $end; | ||||
return $count; | ||||
}; | ||||
} | ||||
} | ||||
sub import { | sub import { | |||
my ($class) = @_; | my ($class) = @_; | |||
my ($file,$offset) = (caller)[1,2]; # for error reporting | my ($file,$offset) = (caller)[1,2]; # for error reporting | |||
$offset++; | ||||
## Parse class name into a regexp suitable for filtration | ## Parse class name into a regexp suitable for filtration | |||
my $terminator = terminator_regexp($class); | filter_add(PDL::NiceSlice::FilterUtilCall::make_filter($class, $file, $offse | |||
t+1)); | ||||
filter_add( | ||||
sub { | ||||
my ($status, $off, $end); | ||||
my $count = 0; | ||||
my $data = ""; | ||||
while ($status = filter_read()) { | ||||
return $status if $status < 0; | ||||
if (defined($terminator) && m/$terminator/) { | ||||
$off=1; | ||||
last; | ||||
} | ||||
if (m/^\s*(__END__|__DATA__)\s*$/) { | ||||
$end=$1; $off = 1; | ||||
last; | ||||
} | ||||
$data .= $_; | ||||
$count++; | ||||
$_ = ""; | ||||
} | ||||
$_ = $data; | ||||
$_ = findslice $_ unless $status < 0; # the actual filter | ||||
$_ .= "no $class;\n" if $off; | ||||
$_ .= "$end\n" if $end; | ||||
return $count; | ||||
} | ||||
); | ||||
} | } | |||
sub unimport { | sub unimport { | |||
filter_del(); | filter_del(); | |||
} | } | |||
1; | 1; | |||
End of changes. 3 change blocks. | ||||
38 lines changed or deleted | 34 lines changed or added |