[Catalyst-commits] r7947 - in Catalyst-Runtime/5.80/trunk: . lib
lib/Catalyst lib/Catalyst/Request t
groditi at dev.catalyst.perl.org
groditi at dev.catalyst.perl.org
Mon Jun 23 21:58:05 BST 2008
Author: groditi
Date: 2008-06-23 21:58:04 +0100 (Mon, 23 Jun 2008)
New Revision: 7947
Added:
Catalyst-Runtime/5.80/trunk/TODO
Modified:
Catalyst-Runtime/5.80/trunk/
Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Action.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/ActionChain.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/ActionContainer.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Request.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Request/Upload.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Response.pm
Catalyst-Runtime/5.80/trunk/t/03podcoverage.t
Log:
r16884 at martha (orig r7477): konobi | 2008-03-11 01:25:42 -0400
Initial commit of Moosified Catalyst parts.
Property changes on: Catalyst-Runtime/5.80/trunk
___________________________________________________________________
Name: svk:merge
- 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:7576
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst:4483
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442
+ 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:7576
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/moose:7477
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst:4483
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442
Added: Catalyst-Runtime/5.80/trunk/TODO
===================================================================
--- Catalyst-Runtime/5.80/trunk/TODO (rev 0)
+++ Catalyst-Runtime/5.80/trunk/TODO 2008-06-23 20:58:04 UTC (rev 7947)
@@ -0,0 +1,12 @@
+
+ - Add Class::Accessor compats
+ * Catalyst::Request
+ * Catalyst::Response
+ * Catalyst::Dispatcher
+ * Catalyst::Request::Upload
+ * Catalyst::Action
+ * Catalyst::ActionChain
+ * Catalyst::ActionContainer
+
+ - Make classes immutable at setup() time
+
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Action.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Action.pm 2008-06-23 20:39:28 UTC (rev 7946)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Action.pm 2008-06-23 20:58:04 UTC (rev 7947)
@@ -1,9 +1,5 @@
package Catalyst::Action;
-use strict;
-use base qw/Class::Accessor::Fast/;
-
-
=head1 NAME
Catalyst::Action - Catalyst Action
@@ -21,12 +17,25 @@
=cut
-__PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/);
+use Moose;
+has class => (is => 'rw');
+has namespace => (is => 'rw');
+has 'reverse' => (is => 'rw');
+has attributes => (is => 'rw');
+has name => (is => 'rw');
+has code => (is => 'rw');
+
+no Moose;
+
+no warnings 'recursion';
+
+#__PACKAGE__->mk_accessors(qw/class namespace reverse attributes name code/);
+
use overload (
# Stringify to reverse for debug output etc.
- q{""} => sub { shift->{reverse} },
+ q{""} => sub { shift->reverse() },
# Codulate to execute to invoke the encapsulated action coderef
'&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
@@ -44,7 +53,7 @@
sub execute {
my $self = shift;
- $self->{code}->(@_);
+ $self->code->(@_);
}
sub match {
@@ -100,6 +109,10 @@
returns the sub name of this action.
+=head2 meta
+
+Provided by Moose
+
=head1 AUTHOR
Matt S. Trout
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/ActionChain.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/ActionChain.pm 2008-06-23 20:39:28 UTC (rev 7946)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/ActionChain.pm 2008-06-23 20:58:04 UTC (rev 7947)
@@ -1,8 +1,9 @@
package Catalyst::ActionChain;
-use strict;
-use base qw/Catalyst::Action/;
+use Moose;
+extends qw(Catalyst::Action);
+has chain => (is => 'rw');
=head1 NAME
@@ -20,8 +21,6 @@
=cut
-__PACKAGE__->mk_accessors(qw/chain/);
-
use overload (
# Stringify to reverse for debug output etc.
@@ -79,8 +78,10 @@
Takes a list of Catalyst::Action objects and constructs and returns a
Catalyst::ActionChain object representing a chain of these actions
-=cut
+=head2 meta
+Provided by Moose
+
=head1 AUTHOR
Matt S. Trout
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/ActionContainer.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/ActionContainer.pm 2008-06-23 20:39:28 UTC (rev 7946)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/ActionContainer.pm 2008-06-23 20:58:04 UTC (rev 7947)
@@ -1,8 +1,5 @@
package Catalyst::ActionContainer;
-use strict;
-use base qw/Class::Accessor::Fast/;
-
=head1 NAME
Catalyst::ActionContainer - Catalyst Action Container
@@ -18,25 +15,20 @@
=cut
-__PACKAGE__->mk_accessors(qw/part actions/);
+use Moose;
-use overload (
+has part => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
+has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
- # Stringify to path part for tree search
- q{""} => sub { shift->{part} },
+around 'new' => sub {
+ my $next = shift;
+ my ($self, $params) = @_;
+ $params = { part => $params } unless ref $params;
+ $next->($self, $params);
+};
-);
+no Moose;
-sub new {
- my ( $class, $fields ) = @_;
-
- $fields = { part => $fields, actions => {} } unless ref $fields;
-
- $class->SUPER::new($fields);
-}
-
-
-
sub get_action {
my ( $self, $name ) = @_;
return $self->actions->{$name} if defined $self->actions->{$name};
@@ -78,6 +70,10 @@
Accessor to the path part this container resolves to. Also what the container
stringifies to.
+=head2 meta
+
+Provided by Moose
+
=head1 AUTHOR
Matt S. Trout
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm 2008-06-23 20:39:28 UTC (rev 7946)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Dispatcher.pm 2008-06-23 20:58:04 UTC (rev 7947)
@@ -1,7 +1,7 @@
package Catalyst::Dispatcher;
-use strict;
-use base 'Class::Accessor::Fast';
+use Moose;
+
use Catalyst::Exception;
use Catalyst::Utils;
use Catalyst::Action;
@@ -16,13 +16,6 @@
# Stringify to class
use overload '""' => sub { return ref shift }, fallback => 1;
-__PACKAGE__->mk_accessors(
- qw/tree dispatch_types registered_dispatch_types
- method_action_class action_container_class
- preload_dispatch_types postload_dispatch_types
- action_hash container_hash
- /
-);
# Preload these action types
our @PRELOAD = qw/Index Path Regex/;
@@ -30,6 +23,18 @@
# Postload these action types
our @POSTLOAD = qw/Default/;
+has _tree => (is => 'rw');
+has _dispatch_types => (is => 'rw');
+has _registered_dispatch_types => (is => 'rw');
+has _method_action_class => (is => 'rw');
+has _action_container_class => (is => 'rw');
+has preload_dispatch_types => (is => 'rw', required => 1, lazy => 1, default => sub { [@PRELOAD] });
+has postload_dispatch_types => (is => 'rw', required => 1, lazy => 1, default => sub { [@POSTLOAD] });
+has _action_hash => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
+has _container_hash => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
+
+no Moose;
+
=head1 NAME
Catalyst::Dispatcher - The Catalyst Dispatcher
@@ -51,24 +56,13 @@
=cut
-sub new {
- my $self = shift;
- my $class = ref($self) || $self;
+sub BUILD {
+ my ($self, $params) = @_;
- my $obj = $class->SUPER::new(@_);
+ my $container =
+ Catalyst::ActionContainer->new( { part => '/', actions => {} } );
- # set the default pre- and and postloads
- $obj->preload_dispatch_types( \@PRELOAD );
- $obj->postload_dispatch_types( \@POSTLOAD );
- $obj->action_hash( {} );
- $obj->container_hash( {} );
-
- # Create the root node of the tree
- my $container =
- Catalyst::ActionContainer->new( { part => '/', actions => {} } );
- $obj->tree( Tree::Simple->new( $container, Tree::Simple->ROOT ) );
-
- return $obj;
+ $self->_tree( Tree::Simple->new( $container, Tree::Simple->ROOT ) );
}
=head2 $self->preload_dispatch_types
@@ -173,6 +167,8 @@
#push @$args, @_;
+ no warnings 'recursion';
+
local $c->request->{arguments} = \@args;
$action->dispatch( $c );
@@ -227,7 +223,7 @@
my $class = $self->_find_component_class( $c, $component ) || return 0;
if ( my $code = $class->can($method) ) {
- return $self->method_action_class->new(
+ return $self->_method_action_class->new(
{
name => $method,
code => $code,
@@ -272,7 +268,7 @@
# Check out dispatch types to see if any will handle the path at
# this level
- foreach my $type ( @{ $self->dispatch_types } ) {
+ foreach my $type ( @{ $self->_dispatch_types } ) {
last DESCEND if $type->match( $c, $path );
}
@@ -303,7 +299,7 @@
$namespace = join( "/", grep { length } split '/', $namespace || "" );
- return $self->action_hash->{"$namespace/$name"};
+ return $self->_action_hash->{"$namespace/$name"};
}
=head2 $self->get_action_by_path( $path );
@@ -316,7 +312,7 @@
my ( $self, $path ) = @_;
$path =~ s/^\///;
$path = "/$path" unless $path =~ /\//;
- $self->action_hash->{$path};
+ $self->_action_hash->{$path};
}
=head2 $self->get_actions( $c, $action, $namespace )
@@ -349,11 +345,11 @@
if ( length $namespace ) {
do {
- push @containers, $self->container_hash->{$namespace};
+ push @containers, $self->_container_hash->{$namespace};
} while ( $namespace =~ s#/[^/]+$## );
}
- return reverse grep { defined } @containers, $self->container_hash->{''};
+ return reverse grep { defined } @containers, $self->_container_hash->{''};
my @parts = split '/', $namespace;
}
@@ -372,7 +368,7 @@
sub uri_for_action {
my ( $self, $action, $captures) = @_;
$captures ||= [];
- foreach my $dispatch_type ( @{ $self->dispatch_types } ) {
+ foreach my $dispatch_type ( @{ $self->_dispatch_types } ) {
my $uri = $dispatch_type->uri_for_action( $action, $captures );
return( $uri eq '' ? '/' : $uri )
if defined($uri);
@@ -391,7 +387,7 @@
sub register {
my ( $self, $c, $action ) = @_;
- my $registered = $self->registered_dispatch_types;
+ my $registered = $self->_registered_dispatch_types;
my $priv = 0;
foreach my $key ( keys %{ $action->attributes } ) {
@@ -399,13 +395,13 @@
my $class = "Catalyst::DispatchType::$key";
unless ( $registered->{$class} ) {
eval "require $class";
- push( @{ $self->dispatch_types }, $class->new ) unless $@;
+ push( @{ $self->_dispatch_types }, $class->new ) unless $@;
$registered->{$class} = 1;
}
}
# Pass the action to our dispatch types so they can register it if reqd.
- foreach my $type ( @{ $self->dispatch_types } ) {
+ foreach my $type ( @{ $self->_dispatch_types } ) {
$type->register( $c, $action );
}
@@ -417,14 +413,14 @@
# Set the method value
$container->add_action($action);
- $self->action_hash->{"$namespace/$name"} = $action;
- $self->container_hash->{$namespace} = $container;
+ $self->_action_hash->{"$namespace/$name"} = $action;
+ $self->_container_hash->{$namespace} = $container;
}
sub _find_or_create_action_container {
my ( $self, $namespace ) = @_;
- my $tree ||= $self->tree;
+ my $tree ||= $self->_tree;
return $tree->getNodeValue unless $namespace;
@@ -457,14 +453,14 @@
sub setup_actions {
my ( $self, $c ) = @_;
- $self->dispatch_types( [] );
- $self->registered_dispatch_types( {} );
- $self->method_action_class('Catalyst::Action');
- $self->action_container_class('Catalyst::ActionContainer');
+ $self->_dispatch_types( [] );
+ $self->_registered_dispatch_types( {} );
+ $self->_method_action_class('Catalyst::Action');
+ $self->_action_container_class('Catalyst::ActionContainer');
my @classes =
$self->_load_dispatch_types( @{ $self->preload_dispatch_types } );
- @{ $self->registered_dispatch_types }{@classes} = (1) x @classes;
+ @{ $self->_registered_dispatch_types }{@classes} = (1) x @classes;
foreach my $comp ( values %{ $c->components } ) {
$comp->register_actions($c) if $comp->can('register_actions');
@@ -499,12 +495,12 @@
$walker->( $walker, $_, $prefix ) for $parent->getAllChildren;
};
- $walker->( $walker, $self->tree, '' );
+ $walker->( $walker, $self->_tree, '' );
$c->log->debug( "Loaded Private actions:\n" . $privates->draw . "\n" )
if $has_private;
# List all public actions
- $_->list($c) for @{ $self->dispatch_types };
+ $_->list($c) for @{ $self->_dispatch_types };
}
sub _load_dispatch_types {
@@ -519,7 +515,7 @@
eval "require $class";
Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ )
if $@;
- push @{ $self->dispatch_types }, $class->new;
+ push @{ $self->_dispatch_types }, $class->new;
push @loaded, $class;
}
@@ -527,6 +523,10 @@
return @loaded;
}
+=head2 meta
+
+Provided by Moose
+
=head1 AUTHOR
Sebastian Riedel, C<sri at cpan.org>
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Request/Upload.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Request/Upload.pm 2008-06-23 20:39:28 UTC (rev 7946)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Request/Upload.pm 2008-06-23 20:58:04 UTC (rev 7947)
@@ -1,17 +1,41 @@
package Catalyst::Request::Upload;
use strict;
-use base 'Class::Accessor::Fast';
use Catalyst::Exception;
use File::Copy ();
use IO::File ();
use File::Spec::Unix;
-__PACKAGE__->mk_accessors(qw/filename headers size tempname type basename/);
+use Moose;
-sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) }
+has filename => (is => 'rw');
+has headers => (is => 'rw');
+has size => (is => 'rw');
+has tempname => (is => 'rw');
+has type => (is => 'rw');
+has basename => (is => 'rw');
+has fh => (
+ is => 'rw',
+ required => 1,
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+
+ my $fh = IO::File->new($self->tempname, IO::File::O_RDONLY);
+ unless ( defined $fh ) {
+ my $filename = $self->tempname;
+ Catalyst::Exception->throw(
+ message => qq/Can't open '$filename': '$!'/ );
+ }
+
+ return $fh;
+ },
+);
+
+no Moose;
+
=head1 NAME
Catalyst::Request::Upload - handles file upload requests
@@ -69,24 +93,6 @@
Opens a temporary file (see tempname below) and returns an L<IO::File> handle.
-=cut
-
-sub fh {
- my $self = shift;
-
- my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY );
-
- unless ( defined $fh ) {
-
- my $filename = $self->tempname;
-
- Catalyst::Exception->throw(
- message => qq/Can't open '$filename': '$!'/ );
- }
-
- return $fh;
-}
-
=head2 $upload->filename
Returns the client-supplied filename.
@@ -163,6 +169,10 @@
Returns the client-supplied Content-Type.
+=head2 meta
+
+Provided by Moose
+
=head1 AUTHORS
Sebastian Riedel, C<sri at cpan.org>
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Request.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Request.pm 2008-06-23 20:39:28 UTC (rev 7946)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Request.pm 2008-06-23 20:58:04 UTC (rev 7947)
@@ -1,8 +1,5 @@
package Catalyst::Request;
-use strict;
-use base 'Class::Accessor::Fast';
-
use IO::Socket qw[AF_INET inet_aton];
use Carp;
use utf8;
@@ -10,26 +7,116 @@
use URI::https;
use URI::QueryParam;
-__PACKAGE__->mk_accessors(
- qw/action address arguments cookies headers query_keywords match method
- protocol query_parameters secure captures uri user/
+use Moose;
+
+has action => (is => 'rw');
+has address => (is => 'rw');
+has arguments => (is => 'rw', default => sub { [] });
+has cookies => (is => 'rw', default => sub { {} });
+has query_keywords => (is => 'rw');
+has match => (is => 'rw');
+has method => (is => 'rw');
+has protocol => (is => 'rw');
+has query_parameters => (is => 'rw', default => sub { {} });
+has secure => (is => 'rw', default => 0);
+has captures => (is => 'rw', default => sub { [] });
+has uri => (is => 'rw');
+has user => (is => 'rw');
+has headers => (
+ is => 'rw',
+ isa => 'HTTP::Headers',
+ handles => [qw(content_encoding content_length content_type header referer user_agent)],
);
-*args = \&arguments;
-*body_params = \&body_parameters;
-*input = \&body;
-*params = \¶meters;
-*query_params = \&query_parameters;
-*path_info = \&path;
-*snippets = \&captures;
+has _context => (
+ is => 'rw',
+ weak_ref => 1,
+);
-sub content_encoding { shift->headers->content_encoding(@_) }
-sub content_length { shift->headers->content_length(@_) }
-sub content_type { shift->headers->content_type(@_) }
-sub header { shift->headers->header(@_) }
-sub referer { shift->headers->referer(@_) }
-sub user_agent { shift->headers->user_agent(@_) }
+has body_parameters => (
+ is => 'rw',
+ required => 1,
+ lazy => 1,
+ default => sub { {} },
+);
+before body_parameters => sub {
+ my ($self) = @_;
+ $self->_context->prepare_body();
+};
+
+has uploads => (
+ is => 'rw',
+ required => 1,
+ lazy => 1,
+ default => sub { {} },
+);
+
+before uploads => sub {
+ my ($self) = @_;
+ $self->_context->prepare_body;
+};
+
+has parameters => (
+ is => 'rw',
+ required => 1,
+ lazy => 1,
+ default => sub { {} },
+);
+
+before parameters => sub {
+ my ($self, $params) = @_;
+ $self->_context->prepare_body();
+ if ( $params && !ref $params ) {
+ $self->_context->log->warn(
+ "Attempt to retrieve '$params' with req->params(), " .
+ "you probably meant to call req->param('$params')" );
+ $params = undef;
+ }
+
+};
+
+has base => (
+ is => 'rw',
+ required => 1,
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ if( $self->uri ){
+ return $self->path;
+ }
+ },
+);
+
+has body => (
+ is => 'rw'
+);
+
+before body => sub {
+ my ($self) = @_;
+ $self->_context->prepare_body();
+};
+
+has hostname => (
+ is => 'rw',
+ required => 1,
+ lazy => 1,
+ default => sub {
+ my ($self) = @_;
+ gethostbyaddr( inet_aton( $self->address ), AF_INET )
+ },
+);
+
+no Moose;
+
+sub args { shift->arguments(@_) }
+sub body_params { shift->body_parameters(@_) }
+sub input { shift->body(@_) }
+sub params { shift->parameters(@_) }
+sub query_params { shift->query_parameters(@_) }
+sub path_info { shift->path(@_) }
+sub snippets { shift->captures(@_) }
+
=head1 NAME
Catalyst::Request - provides information about the current client request
@@ -122,39 +209,11 @@
If your application was queried with the URI
C<http://localhost:3000/some/path> then C<base> is C<http://localhost:3000/>.
-=cut
-
-sub base {
- my ( $self, $base ) = @_;
-
- return $self->{base} unless $base;
-
- $self->{base} = $base;
-
- # set the value in path for backwards-compat
- if ( $self->uri ) {
- $self->path;
- }
-
- return $self->{base};
-}
-
=head2 $req->body
Returns the message body of the request, unless Content-Type is
C<application/x-www-form-urlencoded> or C<multipart/form-data>.
-=cut
-
-sub body {
- my $self = shift;
- $self->{_context}->prepare_body;
-
- return unless $self->{_body};
-
- return $self->{_body}->body;
-}
-
=head2 $req->body_parameters
Returns a reference to a hash containing body (POST) parameters. Values can
@@ -169,15 +228,6 @@
Shortcut for body_parameters.
-=cut
-
-sub body_parameters {
- my ( $self, $params ) = @_;
- $self->{_context}->prepare_body;
- $self->{body_parameters} = $params if $params;
- return $self->{body_parameters};
-}
-
=head2 $req->content_encoding
Shortcut for $req->headers->content_encoding.
@@ -241,23 +291,6 @@
Returns the hostname of the client.
-=cut
-
-sub hostname {
- my $self = shift;
-
- if ( @_ == 0 && not $self->{hostname} ) {
- $self->{hostname} =
- gethostbyaddr( inet_aton( $self->address ), AF_INET );
- }
-
- if ( @_ == 1 ) {
- $self->{hostname} = shift;
- }
-
- return $self->{hostname};
-}
-
=head2 $req->input
Alias for $req->body.
@@ -348,24 +381,6 @@
Shortcut for $req->parameters.
-=cut
-
-sub parameters {
- my ( $self, $params ) = @_;
- $self->{_context}->prepare_body;
- if ( $params ) {
- if ( ref $params ) {
- $self->{parameters} = $params;
- }
- else {
- $self->{_context}->log->warn(
- "Attempt to retrieve '$params' with req->params(), " .
- "you probably meant to call req->param('$params')" );
- }
- }
- return $self->{parameters};
-}
-
=head2 $req->path
Returns the path, i.e. the part of the URI after $req->base, for the current request.
@@ -421,7 +436,7 @@
=cut
-sub read { shift->{_context}->read(@_); }
+sub read { shift->_context->read(@_); }
=head2 $req->referer
@@ -509,15 +524,6 @@
my $upload = $c->request->uploads->{field};
my $upload = $c->request->uploads->{field}->[0];
-=cut
-
-sub uploads {
- my ( $self, $uploads ) = @_;
- $self->{_context}->prepare_body;
- $self->{uploads} = $uploads if $uploads;
- return $self->{uploads};
-}
-
=head2 $req->uri
Returns a URI object for the current request. Stringifies to the URI text.
@@ -562,6 +568,10 @@
Shortcut to $req->headers->user_agent. Returns the user agent (browser)
version string.
+=head2 meta
+
+Provided by Moose
+
=head1 AUTHORS
Sebastian Riedel, C<sri at cpan.org>
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Response.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Response.pm 2008-06-23 20:39:28 UTC (rev 7946)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Response.pm 2008-06-23 20:58:04 UTC (rev 7947)
@@ -1,17 +1,25 @@
package Catalyst::Response;
-use strict;
-use base 'Class::Accessor::Fast';
+use Moose;
-__PACKAGE__->mk_accessors(qw/cookies body headers location status/);
+has cookies => (is => 'rw');
+has body => (is => 'rw');
+has location => (is => 'rw');
+has status => (is => 'rw');
+has headers => (
+ is => 'rw',
+ handles => [qw(content_encoding content_length content_type header)],
+);
-*output = \&body;
+has _context => (
+ is => 'rw',
+ weak_ref => 1,
+);
-sub content_encoding { shift->headers->content_encoding(@_) }
-sub content_length { shift->headers->content_length(@_) }
-sub content_type { shift->headers->content_type(@_) }
-sub header { shift->headers->header(@_) }
+sub output { shift->body(@_) }
+no Moose;
+
=head1 NAME
Catalyst::Response - stores output responding to the current client request
@@ -127,6 +135,10 @@
return $self->location;
}
+=head2 $res->location
+
+Sets or returns the HTTP 'Location'.
+
=head2 $res->status
Sets or returns the HTTP status.
@@ -139,8 +151,12 @@
=cut
-sub write { shift->{_context}->write(@_); }
+sub write { shift->_context->write(@_); }
+=head2 meta
+
+Provided by Moose
+
=head1 AUTHORS
Sebastian Riedel, C<sri at cpan.org>
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2008-06-23 20:39:28 UTC (rev 7946)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2008-06-23 20:58:04 UTC (rev 7947)
@@ -1572,10 +1572,8 @@
}
# For on-demand data
- $c->request->{_context} = $c;
- $c->response->{_context} = $c;
- weaken( $c->request->{_context} );
- weaken( $c->response->{_context} );
+ $c->request->_context($c);
+ $c->response->_context($c);
# Allow engine to direct the prepare flow (for POE)
if ( $c->engine->can('prepare') ) {
Modified: Catalyst-Runtime/5.80/trunk/t/03podcoverage.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/03podcoverage.t 2008-06-23 20:39:28 UTC (rev 7946)
+++ Catalyst-Runtime/5.80/trunk/t/03podcoverage.t 2008-06-23 20:58:04 UTC (rev 7947)
@@ -4,4 +4,8 @@
plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD} || -e 'inc/.author';
-all_pod_coverage_ok();
+all_pod_coverage_ok(
+ {
+ also_private => ['BUILD']
+ }
+);
More information about the Catalyst-commits
mailing list