[Catalyst-commits] r14346 - in
trunk/Catalyst-Plugin-UploadProgress: . lib/Catalyst/Plugin
lib/Catalyst/Plugin/UploadProgress
lib/Catalyst/Plugin/UploadProgress/Role
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Mon Oct 8 19:08:55 GMT 2012
Author: t0m
Date: 2012-10-08 19:08:55 +0000 (Mon, 08 Oct 2012)
New Revision: 14346
Added:
trunk/Catalyst-Plugin-UploadProgress/lib/Catalyst/Plugin/UploadProgress/Role/
trunk/Catalyst-Plugin-UploadProgress/lib/Catalyst/Plugin/UploadProgress/Role/Request.pm
Modified:
trunk/Catalyst-Plugin-UploadProgress/Changes
trunk/Catalyst-Plugin-UploadProgress/Makefile.PL
trunk/Catalyst-Plugin-UploadProgress/lib/Catalyst/Plugin/UploadProgress.pm
Log:
Deal with the Catalyst internals changing - incomplete, needs more tidying up
Modified: trunk/Catalyst-Plugin-UploadProgress/Changes
===================================================================
--- trunk/Catalyst-Plugin-UploadProgress/Changes 2012-10-04 18:39:54 UTC (rev 14345)
+++ trunk/Catalyst-Plugin-UploadProgress/Changes 2012-10-08 19:08:55 UTC (rev 14346)
@@ -1,5 +1,9 @@
Revision history for Perl extension Catalyst::Plugin::UploadProgress
+ - Fix to work with newer versions of Catalyst (FIXME - version no??)
+ where logic is moved into the request class, by applying a request
+ class role if appropriate.
+
0.05 2010-01-12 00:22:05
- Convert to a Moose role
- Fixed POD coverage.
Modified: trunk/Catalyst-Plugin-UploadProgress/Makefile.PL
===================================================================
--- trunk/Catalyst-Plugin-UploadProgress/Makefile.PL 2012-10-04 18:39:54 UTC (rev 14345)
+++ trunk/Catalyst-Plugin-UploadProgress/Makefile.PL 2012-10-08 19:08:55 UTC (rev 14346)
@@ -9,6 +9,7 @@
requires 'Catalyst::Runtime' => '5.80004';
requires 'Moose';
+requires 'MooseX::RelatedClassRoles';
requires 'namespace::autoclean';
author_requires 'Test::Pod' => '1.14';
Added: trunk/Catalyst-Plugin-UploadProgress/lib/Catalyst/Plugin/UploadProgress/Role/Request.pm
===================================================================
--- trunk/Catalyst-Plugin-UploadProgress/lib/Catalyst/Plugin/UploadProgress/Role/Request.pm (rev 0)
+++ trunk/Catalyst-Plugin-UploadProgress/lib/Catalyst/Plugin/UploadProgress/Role/Request.pm 2012-10-08 19:08:55 UTC (rev 14346)
@@ -0,0 +1,39 @@
+package Catalyst::Plugin::UploadProgress::Role::Request;
+use Moose::Role;
+use namespace::autoclean;
+
+has _cache => (
+ required => 1,
+ handles => [qw/ get set /],
+);
+
+around 'prepare_body_chunk' => sub {
+ my ( $orig, $self, $chunk, @args ) = @_;
+
+ $self->$orig($chunk, @args);
+
+ my $id = $self->query_parameters->{progress_id};
+
+ if ( $id ) {
+ # store current progress in cache
+ my $progress = $self->get( 'upload_progress_' . $id );
+
+ if ( !defined $progress ) {
+ # new upload
+ $progress = {
+ size => $self->_body->content_length,
+ received => length $chunk,
+ };
+
+ $self->set( 'upload_progress_' . $id, $progress );
+ }
+ else {
+ $progress->{received} += length $chunk;
+
+ $self->set( 'upload_progress_' . $id, $progress );
+ }
+ }
+};
+
+1;
+
Modified: trunk/Catalyst-Plugin-UploadProgress/lib/Catalyst/Plugin/UploadProgress.pm
===================================================================
--- trunk/Catalyst-Plugin-UploadProgress/lib/Catalyst/Plugin/UploadProgress.pm 2012-10-04 18:39:54 UTC (rev 14345)
+++ trunk/Catalyst-Plugin-UploadProgress/lib/Catalyst/Plugin/UploadProgress.pm 2012-10-08 19:08:55 UTC (rev 14346)
@@ -1,6 +1,7 @@
package Catalyst::Plugin::UploadProgress;
use Moose::Role;
use Catalyst::Exception;
+use MooseX::RelatedClassRoles ();
use namespace::autoclean;
our $VERSION = '0.05';
@@ -12,34 +13,12 @@
setup_finalize
/;
-# I'm concerned that this doesn't call super() at all..
-around 'prepare_body_chunk' => sub {
- my ( $orig, $c, $chunk ) = @_;
- my $body = $c->request->{_body};
- $body->add( $chunk );
-
- my $id = $c->req->query_parameters->{progress_id};
-
- if ( $id ) {
- # store current progress in cache
- my $progress = $c->cache->get( 'upload_progress_' . $id );
-
- if ( !defined $progress ) {
- # new upload
- $progress = {
- size => $body->content_length,
- received => length $chunk,
- };
-
- $c->cache->set( 'upload_progress_' . $id, $progress );
- }
- else {
- $progress->{received} += length $chunk;
-
- $c->cache->set( 'upload_progress_' . $id, $progress );
- }
- }
+around _build_request_class_construction_parameters => sub {
+ my ($orig, $self, @args) = @_;
+ my $p = $self->$orig(@args);
+ $p->{_cache} = $self->cache;
+ return $p;
};
around 'prepare_body' => sub {
@@ -99,6 +78,11 @@
message => 'UploadProgress requires a cache plugin.'
);
}
+ if ($c->request_class->can('prepare_body_chunk')) {
+ Class::MOP::class_of('MooseX::RelatedClassRoles')
+ ->apply($c->meta, name => 'request', require_class_accessor => 0);
+ $c->apply_request_class_roles('Catalyst::Plugin::UploadProgress::Role::Request');
+ }
};
sub upload_progress {
More information about the Catalyst-commits
mailing list