perl_mlb
view release on metacpan or search on metacpan
os2/Filter/Util/Call.pm view on Meta::CPAN
# Call.pm
#
# Copyright (c) 1995-2001 Paul Marquess. All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Filter::Util::Call ;
require 5.002 ;
require DynaLoader;
require Exporter;
use Carp ;
use strict;
use warnings;
use vars qw($VERSION @ISA @EXPORT) ;
@ISA = qw(Exporter DynaLoader);
@EXPORT = qw( filter_add filter_del filter_read filter_read_exact) ;
$VERSION = "1.0601" ;
sub filter_read_exact($)
{
my ($size) = @_ ;
my ($left) = $size ;
my ($status) ;
croak ("filter_read_exact: size parameter must be > 0")
unless $size > 0 ;
# try to read a block which is exactly $size bytes long
while ($left and ($status = filter_read($left)) > 0) {
$left = $size - length $_ ;
}
# EOF with pending data is a special case
return 1 if $status == 0 and length $_ ;
return $status ;
}
sub filter_add($)
{
my($obj) = @_ ;
# Did we get a code reference?
my $coderef = (ref $obj eq 'CODE') ;
# If the parameter isn't already a reference, make it one.
$obj = \$obj unless ref $obj ;
$obj = bless ($obj, (caller)[0]) unless $coderef ;
# finish off the installation of the filter in C.
Filter::Util::Call::real_import($obj, (caller)[0], $coderef) ;
}
bootstrap Filter::Util::Call ;
1;
__END__
=head1 NAME
Filter::Util::Call - Perl Source Filter Utility Module
=head1 SYNOPSIS
use Filter::Util::Call ;
=head1 DESCRIPTION
This module provides you with the framework to write I<Source Filters>
in Perl.
An alternate interface to Filter::Util::Call is now available. See
L<Filter::Simple> for more details.
A I<Perl Source Filter> is implemented as a Perl module. The structure
of the module can take one of two broadly similar formats. To
distinguish between them, the first will be referred to as I<method
filter> and the second as I<closure filter>.
Here is a skeleton for the I<method filter>:
package MyFilter ;
use Filter::Util::Call ;
sub import
{
my($type, @arguments) = @_ ;
filter_add([]) ;
}
sub filter
{
my($self) = @_ ;
my($status) ;
$status = filter_read() ;
$status ;
}
1 ;
and this is the equivalent skeleton for the I<closure filter>:
package MyFilter ;
use Filter::Util::Call ;
sub import
{
my($type, @arguments) = @_ ;
( run in 0.716 second using v1.01-cache-2.11-cpan-364913b4093 )