Skip Menu |

This queue is for tickets about the Catalyst-Plugin-Upload-Image-Magick CPAN distribution.

Report information
The Basics
Id: 45188
Status: resolved
Priority: 0/
Queue: Catalyst-Plugin-Upload-Image-Magick

People
Owner: Nobody in particular
Requestors: bobtfish [...] bobtfish.net
Cc: chisel [...] chizography.net
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.03
Fixed in: (no value)



Subject: PLUGIN BROKEN - Monkeypatching Catalyst classes unsupported in Catalyst 5.80
Your plugin is broken with Catalyst 5.80 as you try to monkeypatch Catalyst::Request::Upload, by calling ->mk_accessors on it. This behavior was never supported and always a bad idea. Please update your code as so that it doesn't do this as suggested in Catalyst::Upgrading Cheers t0m
On Tue Apr 21 09:05:44 2009, BOBTFISH wrote: Show quoted text
> Your plugin is broken with Catalyst 5.80 as you try to monkeypatch > Catalyst::Request::Upload, by calling ->mk_accessors on it. > > This behavior was never supported and always a bad idea. Please update > your code as so that it doesn't do this as suggested in
Catalyst::Upgrading I'm seeing the same thing after upgrading to Catalyst 5.8: Could not load class (Catalyst::Plugin::Upload::Image::Magick::Thumbnail) because : You are trying to modify Catalyst::Request::Upload, which has been made immutable, this is not supported. Try subclassing Catalyst::Request::Upload, rather than monkeypatching it at /usr/local/share/perl/5.10.0/MooseX/Emulate/Class/Accessor/Fast.pm line 107 Catalyst::Component::mk_accessors('Catalyst::Request::Upload', '_thumbnail_temp') called at /usr/local/share/perl/5.10.0/Catalyst/Plugin/Upload/Image/Magick/Thumbnail.pm line 128 require Catalyst/Plugin/Upload/Image/Magick/Thumbnail.pm called at /usr/local/lib/perl/5.10.0/Class/MOP.pm line 138 eval {...} called at /usr/local/lib/perl/5.10.0/Class/MOP.pm line 138 Class::MOP::_try_load_one_class('Catalyst::Plugin::Upload::Image::Magick::Thumbnail') called at /usr/local/lib/perl/5.10.0/Class/MOP.pm line 101 Class::MOP::load_first_existing_class('Catalyst::Plugin::Upload::Image::Magick::Thumbnail') called at /usr/local/lib/perl/5.10.0/Class/MOP.pm line 144 Class::MOP::load_class('Catalyst::Plugin::Upload::Image::Magick::Thumbnail') called at /usr/local/share/perl/5.10.0/Catalyst.pm line 2453 Catalyst::_register_plugin('Cleavages', 'Catalyst::Plugin::Upload::Image::Magick::Thumbnail') called at /usr/local/share/perl/5.10.0/Catalyst.pm line 2479 Catalyst::setup_plugins('Cleavages', 'ARRAY(0xa268700)') called at /usr/local/share/perl/5.10.0/Catalyst.pm line 1003 Catalyst::setup('Cleavages') called at /home/chisel/development/cleavag.es/Cleavages/trunk/script/../lib/Cleavages.pm line 63 require Cleavages.pm called at script/cleavages_server.pl line 55 Compilation failed in require at /usr/local/lib/perl/5.10.0/Class/MOP.pm line 138. at /usr/local/lib/perl/5.10.0/Class/MOP.pm line 124 Class::MOP::load_first_existing_class('Catalyst::Plugin::Upload::Image::Magick::Thumbnail') called at /usr/local/lib/perl/5.10.0/Class/MOP.pm line 144 Class::MOP::load_class('Catalyst::Plugin::Upload::Image::Magick::Thumbnail') called at /usr/local/share/perl/5.10.0/Catalyst.pm line 2453 Catalyst::_register_plugin('Cleavages', 'Catalyst::Plugin::Upload::Image::Magick::Thumbnail') called at /usr/local/share/perl/5.10.0/Catalyst.pm line 2479 Catalyst::setup_plugins('Cleavages', 'ARRAY(0xa268700)') called at /usr/local/share/perl/5.10.0/Catalyst.pm line 1003 Catalyst::setup('Cleavages') called at /home/chisel/development/cleavag.es/Cleavages/trunk/script/../lib/Cleavages.pm line 63 require Cleavages.pm called at script/cleavages_server.pl line 55 Compilation failed in require at script/cleavages_server.pl line 55.
From: abryan+bc [...] pangeamedia.com
FYI to anyone that requires this plugin, you can do what I had to do to get it working (see attached files). First I created a subclass of Catalyst::Request::Upload called Catalyst::Request::Upload::Image::Magick to implement the desired functionality of this plugin. Secondly, I recreated Catalyst::Plugin::Upload::Image::Magick to "upgrade" the upload objects after they have been created. This was done by wrapping around the prepare_uploads catalyst method. I figured I had to do this because Catalyst doesn't provide a way to specify an alternate class to use for creating the upload objects, and this was as close as I could get to hooking into the process. It seems to work, but there is likely a better way. If there is I'd love to hear about it! -- Andrew Bryan abryan+bc@pangeamedia.com
package Catalyst::Request::Upload::Image::Magick; use Moose; with 'MooseX::Emulate::Class::Accessor::Fast'; extends 'Catalyst::Request::Upload'; use Catalyst::Exception; use Image::Magick; use namespace::clean -except => 'meta'; has magick => ( is => 'rw' ); sub image { my $self = shift; unless ( $self->magick ) { my $image = Image::Magick->new; $self->type && (split( '/', $self->type ))[0] eq 'image' or return; my $result = $image->Read( file => $self->fh ); $result and Catalyst::Exception->throw($result); $self->magick($image); } return $self->magick; } sub is_image { my $self = shift; return !!$self->image; } sub width { my $self = shift; $self->image or return; return $self->image->get('width'); } sub height { my $self = shift; $self->image or return; return $self->image->get('height'); } no Moose; __PACKAGE__->meta->make_immutable; 1;
package Catalyst::Plugin::Upload::Image::Magick; use strict; use warnings; use Catalyst::Request::Upload::Image::Magick; sub prepare_uploads { my $c = shift; $c->maybe::next::method(@_); # upgrade existing Catalyst::Request::Upload objects foreach my $param ( keys %{ $c->request->uploads } ) { my $uploads = $c->request->uploads->{ $param }; $uploads = [$uploads] unless ref $uploads eq 'ARRAY'; my @upgraded = (); foreach my $upload ( @$uploads ) { # is there a better more Moosey way than this? push @upgraded, Catalyst::Request::Upload::Image::Magick->new(+{%$upload}); } $c->request->uploads->{ $param } = @upgraded > 1 ? \@upgraded : $upgraded[0]; } return; } 1;
Hi all, I've uploaded a new version and the bug should be fixed now. This plugin should now work with Catalyst >= 5.80 Adam