[Bps-public-commit] r19749 - in Net-Google-Code/trunk: lib/Net/Google/Code/Issue
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Thu May 21 03:24:50 EDT 2009
Author: sunnavy
Date: Thu May 21 03:24:50 2009
New Revision: 19749
Modified:
Net-Google-Code/trunk/Makefile.PL
Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Attachment.pm
Log:
google does *not* parse content type of download at all, we need to parse it ourselves
Modified: Net-Google-Code/trunk/Makefile.PL
==============================================================================
--- Net-Google-Code/trunk/Makefile.PL (original)
+++ Net-Google-Code/trunk/Makefile.PL Thu May 21 03:24:50 2009
@@ -13,6 +13,8 @@
requires 'HTML::TreeBuilder';
requires 'Params::Validate';
requires 'DateTime';
+requires 'MIME::Types';
+requires 'File::MMagic';
recursive_author_tests('xt/');
Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Attachment.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Attachment.pm (original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Attachment.pm Thu May 21 03:24:50 2009
@@ -2,6 +2,8 @@
use Moose;
with 'Net::Google::Code::Role::Fetchable', 'Net::Google::Code::Role::HTMLTree';
use Scalar::Util qw/blessed/;
+use MIME::Types;
+use File::MMagic;
has 'name' => ( isa => 'Str', is => 'rw' );
has 'url' => ( isa => 'Str', is => 'rw' );
@@ -72,10 +74,22 @@
}
sub load {
- my $self = shift;
+ my $self = shift;
my $content = $self->fetch( $self->url );
- $self->content( $content );
- $self->content_type( $self->mech->response->header( 'Content-Type' ) );
+ $self->content($content);
+ my $content_type;
+
+ # google code doesn't parse download's content type at all, we need to
+ # figure it out by ourselves
+ my $mime_type = MIME::Types->new->mimeTypeOf( $self->name );
+ if ($mime_type) {
+ $content_type = $mime_type->type;
+ }
+ else {
+ $content_type = File::MMagic->new->checktype_contents($content);
+ }
+
+ $self->content_type( $content_type || 'application/octet-stream' );
}
no Moose;
@@ -124,10 +138,13 @@
=item id
+=item load
+
=item content
=item content_type
+
=back
=head1 AUTHOR
More information about the Bps-public-commit
mailing list