Apache-CGI-Builder
view release on metacpan or search on metacpan
lib/Apache/CGI/Builder.pm view on Meta::CPAN
package Apache::CGI::Builder ;
$VERSION = 1.3 ;
use strict ;
# This file uses the "Perlish" coding style
# please read http://perl.4pro.net/perlish_coding_style.html
; use Carp
; $Carp::Internal{+__PACKAGE__}++
; use mod_perl
; our $usage = << ''
Apache2::CGI::Builder should be used INSTEAD of CGI::Builder and should not be included as an extension
; my $MP2
; BEGIN
{ require File::Basename
; if ( $MP2 = $mod_perl::VERSION >= 1.99 )
{ require Apache::RequestRec
; require Apache::Response
; require ModPerl::Util
; require Apache::Const
; Apache::Const->import( -compile => 'OK' )
; *PerlResponseHandler = sub { shift()->PerlHandler(@_) }
; *handler = sub : method
{ shift()->Apache::CGI::Builder::_::dispatcher(@_)
}
}
else
{ require Apache::Constants
; Apache::Constants->import( 'OK' )
; *handler = sub ($$)
{ shift()->Apache::CGI::Builder::_::dispatcher(@_)
}
}
}
; sub import
{ undef $usage
; require CGI::Builder
; unshift @_, 'CGI::Builder'
; goto &CGI::Builder::import
}
; use Class::props
{ name => 'no_page_content_status'
, default => '404 Not Found'
}
; use Object::props
{ name => 'r'
, default => sub{ Apache->request }
}
; sub PerlHandler
{ my $s = shift
; $s = $s->new() unless ref $s
; $s->process()
; $MP2
? Apache::OK()
: Apache::Constants::OK()
}
; sub OH_init
{ my $s = shift
; $ENV{MOD_PERL}
or croak 'Cannot use Apache::CGI::Builder without mod_perl, died'
; my $filename = $s->r->filename
; my ( $page_name, $page_path, $page_suffix )
; if (-d $filename)
{ $page_path = $filename
}
else
{ ( $page_name, $page_path, $page_suffix )
= File::Basename::fileparse ( $filename
, qr/\..+$/
)
}
; $s->page_name($page_name) unless defined $$s{page_name}
; $s->page_path($page_path) unless defined $$s{page_path}
; $s->page_suffix($page_suffix) unless defined $$s{page_suffix}
}
; sub Apache::CGI::Builder::_::dispatcher
{ my ($s, $r) = @_
; my $cur = $MP2
? ModPerl::Util::current_callback()
: $r->current_callback
; if ( my $h = $s->can($cur) )
{ $h->(@_)
}
else
{ croak sprintf '"%s" does not implement any "%s" method, died'
, ref $s
, $cur
}
}
; 1
__END__
=pod
=head1 NAME
Apache::CGI::Builder - CGI::Builder and Apache/mod_perl (1 and 2) integration
lib/Apache/CGI/Builder.pm view on Meta::CPAN
SetHandler perl-script
PerlHandler FooBar
</IfModule>
=back
B<Note>: see also the F</magic_examples/perl_side_include/.htaccess> file in this distribution.
=head1 METHODS
This module adds a few internally used methods to your CBB. You don't need to use them directly, but you should know that they exist in order to avoid to unwittingly override them.
=over
=item handler
Generic method used as a method handler dispatcher
=item PerlHandler
This method is used as the response method handler
=item PerlResponseHandler
PerlHandler alias used by mod_perl 2
=back
=head2 OH_init
This method internally initializes the C<page_name>, C<page_path>, C<page_suffix> defaults.
=head1 PROPERTY ACCESSORS
=head2 r
This is the only property added to the standard C<CGI::Builder> properties. It is set to the Apache request object: use it to interact directly with all the Apache/mod_perl internal methods.
=head2 CBF changed property defaults
=head3 CBF page_name
The default page_name is set to the base name of the requested filename (e.g. being the requested filename F</path/to/file.mhtml>, the default page_name will be set to 'file'). This is an alternative and handy way to avoid to pass the page_name with ...
B<Note>:In case you have to handle a file with a multiple suffix like 'file.tar.gz' the C<page_name> will be 'file'
=head3 CBF page_path
The default C<page_path> property is set to the directory that contains the requested file.
=head3 CBF page_suffix
The default C<page_suffix> property is set to the suffix of the requested filename (e.g. being the requested filename F</path/to/file.mhtml>, the default page_suffix will be set to '.mhtml').
B<Note>:In case you have to handle a file with a multiple suffix like 'file.tar.gz' the C<suffix> will be '.tar.gz'
=head1 CBF Overriding
=head2 CBF no_page_content_status
This extension overrides this class property by just changing the '204 No Content' (that the CBF sets when no page_content has been produced by the process), with a more consistent '404 Not Found' status. It does so because the client is requesting a...
=head1 Selfloading Perl*Handlers
The CBB that uses this module, will have a special feature: a sort of Selfloading of Perl*Handlers.
When you pass a CBB class (or an instance of the CBB) as a Perl*Handler, this module will use (as the method handler) the method called with the same name of the Perl*Handler. For example:
PerlAnyHandler My::CBB
which normally would mean:
PerlAnyHandler My::CBB->handler
get interpreted by this module as:
PerlAnyHandler My::CBB->PerlAnyHandler
This means that if any extension needs to implement any handler, it could just define a Perl*Handler() method with the same name, and recommend the use of the CBB class as that particular Perl*Handler. This feature adds some encapsulation and simplif...
B<Note>: the user could explicitly bypass this feature by using explicit method handlers e.g.:
PerlAnyHandler My::CBB->AnySpecialHandler
=head1 SUPPORT
See L<CGI::Builder/"SUPPORT">.
=head1 AUTHOR and COPYRIGHT
© 2004 by Domizio Demichelis (L<http://perl.4pro.net>)
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.
=cut
( run in 1.210 second using v1.01-cache-2.11-cpan-98e64b0badf )