Apache2-REST
view release on metacpan or search on metacpan
lib/Apache2/REST.pm view on Meta::CPAN
}
}
my $handlerRootClass = $r->dir_config('Apache2RESTHandlerRootClass') || 'Apache2::REST::Handler' ;
eval "require $handlerRootClass;";
if ( $@ ){
die "Cannot find root class $handlerRootClass (from conf Apache2RESTHandlerRootClass): $@\n" ;
}
my $topHandler = $handlerRootClass->new() ;
my $conf = Apache2::REST::Conf->new() ;
$conf->Apache2RESTErrorOutput($r->dir_config('Apache2RESTErrorOutput') || 'both' );
$topHandler->conf($conf);
my @stack = split('\/+' , $uri);
# Protect against empty fragments.
@stack = grep { length($_)>0 } @stack ;
$retCode = $topHandler->handle(\@stack , $req , $resp ) ;
output:
## Load the writer for the given format
my $defaultWriter = $r->dir_config('Apache2RESTWriterDefault') || 'xml' ;
my $wClass = $_wtClasses->{$req->requestedFormat()} || $_wtClasses->{$defaultWriter} ;
if ($resp->stream()){
$wClass .= '_stream';
} elsif ($resp->multipart_stream()) {
$wClass .= '_multipart';
}
eval "require $wClass;" ;
if ( $@ ){
warn "Cannot load $wClass:$@\n" ;
## Silently fail to default writer
require Apache2::REST::Writer::xml ;
$wClass = 'Apache2::REST::Writer::xml' ;
}
my $writer = $wClass->new() ;
if($writer->can('handleModPerlResponse')){
## Use that instead of the legacy code below. (See TODO)
return $writer->handleModPerlResponse($r,$resp,$retCode);
}
## TODO: Refactor that so it goes in a writer specific method
$r->content_type($writer->mimeType($resp)) ;
$resp->cleanup() ;
my $respTxt = $writer->asBytes($resp) ;
if ( $retCode && ( $retCode != Apache2::Const::HTTP_OK ) ){
$r->status($retCode);
}
if ( $retCode && $retCode =~ /^2/ ){
$r->headers_out()->add('Content-length' , length($respTxt)) ;
}else{
$r->err_headers_out()->add('Content-length' , length($respTxt)) ;
}
binmode STDOUT ;
print $respTxt ;
return Apache2::Const::OK ;
}
=head1 AUTHORS
Jerome Eteve, C<< <jerome at eteve.net> >>
Scott Thoman, C<< <scott dot thoman at steeleye dot com> >>
=head1 BUGS
Please report any bugs or feature requests to
L<http://code.google.com/p/apache2rest/issues/list>
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
=head1 SUPPORT
You can find reference documentation for this module with the perldoc command.
perldoc Apache2::REST
You can find the wiki with Cooking recipes and in depth articles at:
L<http://code.google.com/p/apache2rest/w/list>
=over 4
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Apache2-REST>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Apache2-REST>
=item * Search CPAN
L<http://search.cpan.org/dist/Apache2-REST>
=back
=head1 COPYRIGHT & LICENSE
Copyright 2009-2010 The authors, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1; # End of Apache2::REST
( run in 0.903 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )