Filter
view release on metacpan or search on metacpan
Call/Call.pm view on Meta::CPAN
# Call.pm
#
# Copyright (c) 1995-2011 Paul Marquess. All rights reserved.
# Copyright (c) 2011-2014, 2018-2022 Reini Urban. All rights reserved.
# Copyright (c) 2014-2017 cPanel Inc. 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.006 ; # our
require Exporter;
use XSLoader ();
use strict;
use warnings;
our @ISA = qw(Exporter);
our @EXPORT = qw( filter_add filter_del filter_read filter_read_exact) ;
our $VERSION = "1.65" ;
our $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
sub filter_read_exact($)
{
my ($size) = @_ ;
my ($left) = $size ;
my ($status) ;
unless ( $size > 0 ) {
require Carp;
Carp::croak("filter_read_exact: size parameter must be > 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.
if (!$coderef and (!ref($obj) or ref($obj) =~ /^ARRAY|HASH$/)) {
$obj = bless (\$obj, (caller)[0]);
}
# finish off the installation of the filter in C.
Filter::Util::Call::real_import($obj, (caller)[0], $coderef) ;
}
XSLoader::load('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 1.707 second using v1.01-cache-2.11-cpan-13bb782fe5a )