use Maypole::Headers;
use Maypole::Components;
use URI();
+use URI::QueryParam;
+use NEXT;
use File::MMagic::XS qw(:compat);
our $VERSION = '2.11';
__PACKAGE__->mk_accessors(
qw( params query objects model_class template_args output path
args action template error document_encoding content_type table
- headers_in headers_out stash status)
+ headers_in headers_out stash status parent)
);
__PACKAGE__->config( Maypole::Config->new() );
# among other things, this populates $config->classes
$config->model->setup_database($config, $class, @_);
-
+
foreach my $subclass ( @{ $config->classes } ) {
next if $subclass->isa("Maypole::Model::Base");
no strict 'refs';
- unshift @{ $subclass . "::ISA" }, $config->model;
-
+ unshift @{ $subclass . "::ISA" }, $config->model;
}
# Load custom model code, if it exists - nb this must happen after the
return $status;
}
+=back
+
+=head2 component
+
+ Run Maypole sub-requests as components using L<Maypole::Components>
+
+ [% request.component("/beer/view_as_component/20") %]
+
+ Allows you to integrate the results of a Maypole request into an existing
+request. You'll need to set up actions and templates
+which return fragments of HTML rather than entire pages, but once you've
+done that, you can use the C<component> method of the Maypole request object
+to call those actions. You may pass a query string in the usual URL style.
+You should not fully qualify the Maypole URLs.
+
+=cut
+
sub component {
- my ($r,$path) = @_;
- my $component = Maypole::Components->new(@_);
- return $component->handler($path);
+ my ( $r, $path ) = @_;
+ my $self = bless { parent => $r }, ref $r;
+ my $url = URI->new($path);
+ $self->{path} = $url->path;
+ $self->parse_path;
+ $self->params( $url->query_form_hash );
+ $self->query( $r->params );
+ $self->handler_guts;
+ return $self->output;
}
+sub get_template_root {
+ my $self = shift;
+ my $r = shift;
+ return $r->parent->get_template_root if $r->{parent};
+ return $self->NEXT::DISTINCT::get_template_root( $r, @_ );
+}
+
+sub view_object {
+ my $self = shift;
+ my $r = shift;
+ return $r->parent->view_object if $r->{parent};
+ return $self->NEXT::DISTINCT::view_object( $r, @_ );
+}
# Instead of making plugin authors use the NEXT::DISTINCT hoopla to ensure other
# plugins also get to call the hook, we can cycle through the application's
=cut
-sub get_template_root {'.'}
-
=back
=head2 Request properties
+++ /dev/null
-package Maypole::Components;
-use strict;
-use warnings;
-use URI;
-use URI::QueryParam;
-
-our @ISA = qw(Maypole);
-
-sub new {
- my ($class,$r) = @_;
- my $self = bless { config => $r->config, parent => $r }, $class;
-}
-
-sub handler {
- my $self = shift;
- my $path = shift;
- my $url = URI->new($path);
- $self->{path} = $url->path;
- $self->parse_path;
- $self->{query} = $url->query_form_hash;
- $self->handler_guts;
- return $self->{output};
-}
-
-sub get_template_root { shift->{parent}->get_template_root }
-sub view_object { shift->{parent}->view_object }
-
-1;
-__END__
-
-=head1 NAME
-
-Maypole::Components - Run Maypole sub-requests as components
-
-=head1 SYNOPSIS
-
- package BeerDB;
- use base qw(Maypole);
-
-
-
- [% request.component("/beer/view_as_component/20") %]
-
-=head1 DESCRIPTION
-
-This subclass of Maypole allows you to integrate the results of a Maypole
-request into an existing request. You'll need to set up actions and templates
-which return fragments of HTML rather than entire pages, but once you've
-done that, you can use the C<component> method of the Maypole request object
-to call those actions. You may pass a query string in the usual URL style.
-You should not fully qualify the Maypole URLs.
-
-=head1 SEE ALSO
-
-http://maypole.perl.org/
-
-=head1 AUTHOR
-
-Simon Cozens, E<lt>simon@cpan.orgE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2004 by Simon Cozens
-
-=cut