Catalyst-View-GD-0.01/0000755000076500007650000000000010644556474015271 5ustar stevanstevan00000000000000Catalyst-View-GD-0.01/Build.PL0000444000076500007650000000111410644556474016560 0ustar stevanstevan00000000000000use Module::Build; use strict; my $build = Module::Build->new( module_name => 'Catalyst::View::GD', license => 'perl', requires => { 'Catalyst::Runtime' => '0', 'GD' => '0', }, optional => { }, build_requires => { 'Test::More' => '0.62', 'Test::Exception' => '0.21', 'Test::Image::GD' => '0.03', }, create_makefile_pl => 'traditional', recursive_test_files => 1, add_to_cleanup => [ 'META.yml', '*.bak', '*.gz', 'Makefile.PL', ], ); $build->create_build_script; Catalyst-View-GD-0.01/Changes0000444000076500007650000000021410644556474016557 0ustar stevanstevan00000000000000Changes for Catalyst::View::GD 0.01 Monday, July 9, 2007 - I can't believe no one has written this one yet, oh well, here it is.Catalyst-View-GD-0.01/lib/0000755000076500007650000000000010644556474016037 5ustar stevanstevan00000000000000Catalyst-View-GD-0.01/lib/Catalyst/0000755000076500007650000000000010644556474017623 5ustar stevanstevan00000000000000Catalyst-View-GD-0.01/lib/Catalyst/View/0000755000076500007650000000000010644556474020535 5ustar stevanstevan00000000000000Catalyst-View-GD-0.01/lib/Catalyst/View/GD.pm0000444000076500007650000001032210644556474021361 0ustar stevanstevan00000000000000package Catalyst::View::GD; use strict; use warnings; use NEXT; use GD; use Scalar::Util 'blessed'; use Catalyst::Exception; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; use base 'Catalyst::View'; __PACKAGE__->mk_accessors(qw[ gd_image_type gd_image_content_type gd_image_render_args ]); sub new { my($class, $c, $args) = @_; my $self = $class->NEXT::new($c, $args); my $config = $c->config->{'View::GD'}; $args->{gd_image_type} ||= $config->{gd_image_type} || 'gif'; $args->{gd_image_content_type} ||= $config->{gd_image_content_type} || ('image/' . $args->{gd_image_type}); $args->{gd_image_render_args} ||= $config->{gd_image_render_args} || []; $self->gd_image_type($args->{gd_image_type}); $self->gd_image_content_type($args->{gd_image_content_type}); $self->gd_image_render_args($args->{gd_image_render_args}); return $self; } sub process { my $self = shift; my $c = shift; my @args = @_; my $gd_image_type = $c->stash->{gd_image_type} || $self->gd_image_type; my $gd_image_content_type = $c->stash->{gd_image_content_type} || $self->gd_image_content_type; my $gd_image_render_args = $c->stash->{gd_image_render_args} || $self->gd_image_render_args; my $gd_image = $c->stash->{gd_image}; (defined $gd_image) || die "No image to render"; (blessed $gd_image && $gd_image->isa('GD::Image')) || die "Bad image ($gd_image), must be an instance of GD::Image"; my $render_method = $gd_image->can($gd_image_type); (defined $render_method) || die "Cannot render '$gd_image_type' for '$gd_image' : no '$gd_image_type' available"; my $img = eval { $gd_image->$render_method(@{$self->gd_image_render_args}) }; if ($@) { die "Failed to render '$gd_image' as '$gd_image_type' because: $@"; } $c->response->content_type($gd_image_content_type); $c->response->body($img); } 1; __END__ =pod =head1 NAME Catalyst::View::GD - A Catalyst View for GD images =head1 SYNOPSIS # lib/MyApp/View/GD.pm package MyApp::View::GD; use base 'Catalyst::View::GD'; 1; # configure in lib/MyApp.pm MyApp->config({ ... 'View::GD' => { gd_image_type => 'png', # defaults to 'gif' gd_image_content_type => 'images/png', # defaults to 'image/$gd_image_type' gd_image_render_args => [ 5 ], # defaults to [] }, }); sub foo : Local { my($self, $c) = @_; $c->stash->{gd_image} = $self->create_foo_image(); $c->forward('MyApp::View::GD'); } =head1 DESCRIPTION This is a Catalyst View subclass which can handle rendering GD based image content. =head1 CONFIG OPTIONS =over 4 =item I This defaults to C but should be the name of the method to call on the GD::Image instance in order to render the images. =item I This is an array ref of values to be passed as an argument to the GD::Image render method. =item I The default for this is built from the C parameter, which in most cases will just work, but in some more specific rendering methods in GD::Image it will not and you will need to assign this explicitly. =back =head1 METHODS =over 4 =item B This really just handles consuming the configuration parameters. =item B This method will always look in the C stash for an instance of GD::Image and it will then render and serve it according to the configuration setup. It is also possible to override the global configuration on a per-request basis by assigning values in the stash using the same keys as used in the configuration. =back =head1 BUGS All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. =head1 AUTHOR Stevan Little Estevan.little@iinteractive.comE =head1 COPYRIGHT AND LICENSE Copyright 2007 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Catalyst-View-GD-0.01/Makefile.PL0000444000076500007650000000116410644556474017243 0ustar stevanstevan00000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.03 use ExtUtils::MakeMaker; WriteMakefile ( 'PL_FILES' => {}, 'INSTALLDIRS' => 'site', 'NAME' => 'Catalyst::View::GD', 'EXE_FILES' => [], 'VERSION_FROM' => 'lib/Catalyst/View/GD.pm', 'PREREQ_PM' => { 'Test::More' => '0.62', 'Test::Exception' => '0.21', 'GD' => '0', 'Catalyst::Runtime' => '0', 'Test::Image::GD' => '0.03' } ) ; Catalyst-View-GD-0.01/MANIFEST0000444000076500007650000000032410644556474016417 0ustar stevanstevan00000000000000Build.PL Changes Makefile.PL META.yml MANIFEST MANIFEST.SKIP README lib/Catalyst/View/GD.pm t/000_load.t t/001_basic.t t/pod.t t/pod_coverage.t t/images/test_one.gif t/lib/GDTestApp.pm t/lib/GDTestApp/View/GD.pm Catalyst-View-GD-0.01/MANIFEST.SKIP0000444000076500007650000000024510644556474017166 0ustar stevanstevan00000000000000^_build ^Build$ ^blib ~$ \.bak$ ^MANIFEST\.SKIP$ CVS \.svn \.DS_Store cover_db \..*\.sw.?$ ^Makefile$ ^pm_to_blib$ ^MakeMaker-\d ^blibdirs$ \.old$ ^#.*#$ ^\.# ^TODO$Catalyst-View-GD-0.01/META.yml0000444000076500007650000000105410644556474016540 0ustar stevanstevan00000000000000--- name: Catalyst-View-GD version: 0.01 author: - 'Stevan Little Estevan.little@iinteractive.comE' abstract: A Catalyst View for GD images license: perl resources: license: http://dev.perl.org/licenses/ requires: Catalyst::Runtime: 0 GD: 0 build_requires: Test::Exception: 0.21 Test::Image::GD: 0.03 Test::More: 0.62 provides: Catalyst::View::GD: file: lib/Catalyst/View/GD.pm version: 0.01 generated_by: Module::Build version 0.2805 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 Catalyst-View-GD-0.01/README0000444000076500007650000000104610644556474016150 0ustar stevanstevan00000000000000Catalyst::View::GD version 0.01 =========================== See the individual module documentation for more information INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Catalyst::Runtime GD COPYRIGHT AND LICENCE Copyright (C) 2007 Infinity Interactive, Inc. http://www.iinteractive.com This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Catalyst-View-GD-0.01/t/0000755000076500007650000000000010644556474015534 5ustar stevanstevan00000000000000Catalyst-View-GD-0.01/t/000_load.t0000444000076500007650000000016510644556474017217 0ustar stevanstevan00000000000000#!/usr/bin/perl use strict; use warnings; use Test::More no_plan => 1; BEGIN { use_ok('Catalyst::View::GD'); }Catalyst-View-GD-0.01/t/001_basic.t0000444000076500007650000000173010644556474017361 0ustar stevanstevan00000000000000#!/usr/bin/perl use strict; use warnings; use FindBin; use File::Spec; use lib (File::Spec->catdir($FindBin::Bin, 'lib')); use Test::More tests => 7; use Test::Image::GD; use Catalyst::Test 'GDTestApp'; BEGIN { use_ok('Catalyst::View::GD'); } my $TEST_IMAGE_DIR = File::Spec->catdir($FindBin::Bin, 'images'); sub test_image { File::Spec->catfile($TEST_IMAGE_DIR, shift) } { my $response = request('http://localhost/test_one'); ok(defined $response, '... got the response successfully'); ok($response->is_success, '... response is a success'); is($response->code, 200, '... response code is 200'); is_deeply( [ $response->content_type ], [ 'image/gif' ], '... the response content type is image/gif'); my $img = GD::Image->newFromGifData($response->content) || diag "Cannot create new image from data"; isa_ok($img, 'GD::Image'); cmp_image($img, test_image('test_one.gif'), '... our image matched the control'); } Catalyst-View-GD-0.01/t/images/0000755000076500007650000000000010644556474017001 5ustar stevanstevan00000000000000Catalyst-View-GD-0.01/t/images/test_one.gif0000444000076500007650000000046310644556474021311 0ustar stevanstevan00000000000000GIF87add,ddZ.̺qfIvɶzʕM#,>a7&e:uFu:b\V5}1i>'j"{éB~~"#hBsX8èX1ybI)YйA*j )jK1[Xzq ;\9L<|}l\ A}ݠPN>ޮg/?O_o0 <0… :|1ĉ+Z1 ;z2ȑ ;Catalyst-View-GD-0.01/t/lib/0000755000076500007650000000000010644556474016302 5ustar stevanstevan00000000000000Catalyst-View-GD-0.01/t/lib/GDTestApp/0000755000076500007650000000000010644556474020075 5ustar stevanstevan00000000000000Catalyst-View-GD-0.01/t/lib/GDTestApp/View/0000755000076500007650000000000010644556474021007 5ustar stevanstevan00000000000000Catalyst-View-GD-0.01/t/lib/GDTestApp/View/GD.pm0000444000076500007650000000014510644556474021635 0ustar stevanstevan00000000000000package GDTestApp::View::GD; use strict; use warnings; use base 'Catalyst::View::GD'; 1; __END__ Catalyst-View-GD-0.01/t/lib/GDTestApp.pm0000444000076500007650000000140010644556474020424 0ustar stevanstevan00000000000000package GDTestApp; use strict; use warnings; use Catalyst; use GD; use GDTestApp::View::GD; __PACKAGE__->config({ name => 'GDTestApp', 'View::GD' => {} # go with the defaults for now }); __PACKAGE__->setup; sub create_image : Private { my $self = shift; my $img = GD::Image->new(100, 100); my $white = $img->colorAllocate(255, 255, 255); my $black = $img->colorAllocate(0, 0, 0); my $red = $img->colorAllocate(255, 0, 0); $img->rectangle(0, 0, 20, 20, $black); $img->rectangle(20, 20, 50, 50, $red); return $img; } sub test_one : Global { my ($self, $c) = @_; $c->stash->{gd_image} = $self->create_image; $c->forward('GDTestApp::View::GD'); } 1; __END__ Catalyst-View-GD-0.01/t/pod.t0000444000076500007650000000025710644556474016505 0ustar stevanstevan00000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Catalyst-View-GD-0.01/t/pod_coverage.t0000444000076500007650000000031710644556474020355 0ustar stevanstevan00000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok();