package filtertest;
use Filter::Util::Call;
use strict;
use warnings;
use feature "switch";
sub import {
my $self = @_;
my $ref = [];
filter_add( bless $ref );
}
sub filter {
my $self = @_;
my $status;
$status = filter_read();
die "some thing messed up" if $status < 0 ;
die "EOF reached" if $status == 0;
given( $_ ){
when (/^say*/) {
print "\n%%reaching here as $_ was matched%%";
s/say/print/;
print "\n%%It was changed to $_%%";
}
when ( /^use/ ) {
print "\n&&reaching here as $_ was matched&&";
}
default {
print "\n**default condition**"
}
}
$status;
}
1;
####
use strict;
use warnings;
use filtertest;
say 'hello.world';
say 'hello';
####
**default condition**
**default condition**
%%reaching here as say 'hello.world';
was matched%%
%%It was changed to print 'hello.world';
String found where operator expected at filter_test.pl line 9, near "say 'hello.world'"
(Do you need to predeclare say?)
%%
**default condition**
**default condition**
%%reaching here as say 'hello';
was matched%%
%%It was changed to print 'hello';
String found where operator expected at filter_test.pl line 12, near "say 'hello'"
(Do you need to predeclare say?)
syntax error at filter_test.pl line 9, near "say 'hello.world'"
EOF reached at filtertest.pm line 24.
%%