File: FilterUtilCall.pm

package info (click to toggle)
pdl 1%3A2.007-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,848 kB
  • ctags: 6,321
  • sloc: perl: 32,760; fortran: 13,113; ansic: 9,273; makefile: 81; sh: 32
file content (53 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This original Filter::Util::Call-based
# PDL::NiceSlice engine.
#
use Filter::Util::Call;

##############################
# If you mess with the import filter, please also change the pdlpp importer 
# just above this comment!  They both do similar things, but one to an eval string
# and one to an import file.
#   --CED 5-Nov-2007
#
sub import {
    my ($class) = @_;
    ($file,$offset) = (caller)[1,2];  # for error reporting
    $offset++;
    
    ## Parse class name into a regexp suitable for filtration
    my $terminator = terminator_regexp($class);

    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 {
  filter_del();
}

1;