Magick.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 CC 5 SCAR 21.6
CC
5
Cov
0%
image
20.0
is_image
6.0
BEGIN
2.0
CRAP 8.7
1 package Catalyst::Plugin::Upload::Image::Magick;
2  
3 use strict;
4 use warnings;
5  
6 use Catalyst::Request::Upload;
7 use Catalyst::Exception;
8  
9 use Image::Magick;
10  
11 =head1 NAME
12  
13 Catalyst::Plugin::Upload::Image::Magick - Image information plugin for Catalyst::Request::Upload
14  
15 =head1 VERSION
16  
17 Version 0.03
18  
19 =cut
20  
21 our $VERSION = '0.03';
22  
23 =head1 SYNOPSIS
24  
25 In your L<Catalyst> project,
26  
27 use Catalyst qw/Upload::Image::Magick/;
28  
29 And you can execute method around image information in L<Catalyst::Request::Image> object;
30  
31 sub uploaded_action: Local {
32 my ($self, $c) = shift;
33  
34 $upload = $c->request->upload('file_field');
35  
36 if ($upload->is_image) {
37 $c->log->debug("width : " . $upload->width);
38 $c->log->debug("height : " . $upload->height);
39 }
40  
41 # ...
42 }
43  
44 =cut
45  
46 {
47  
48 package Catalyst::Request::Upload;
49  
50 sub image {
51 my $self = shift;
52  
53 unless ( $self->{_image} ) {
54 my $image = Image::Magick->new;
55  
56 return undef if ( !$self->type || [ split( '/', $self->type ) ]->[0] ne 'image' );
57 my $result = $image->Read( file => $self->fh );
58 Catalyst::Exception->throw($result) if ($result);
59  
60 $self->{_image} = $image;
61 }
62  
63 return $self->{_image};
64 }
65  
66 sub is_image {
67 my $self = shift;
68  
69 return ( $self->image ) ? 1 : 0;
70 }
71  
72 for my $method (qw/width height/) {
73 no strict 'refs';
74  
75 *{$method} = sub {
76 my $self = shift;
77  
78 return $self->image->get($method) if ( $self->image );
79 return undef;
80 };
81 }
82 }
83  
84 =head1 METHODS
85  
86 =head2 image()
87  
88 If uploaded file is image, then return L<Image::Magick> object,
89 is't image then throw L<Catalyst::Exception>.
90  
91 =head2 is_image()
92  
93 If uploaded file is image, then return 1, else 0.
94  
95 =head2 width()
96  
97 If uploaded file is image, then return image width, else undef.
98  
99 =head2 height()
100  
101 If uploaded file is image, then return image height, else undef.
102  
103 =head1 AUTHOR
104  
105 Toru Yamaguchi, C<< <zigorou at cpan.org> >>
106  
107 =head1 SEE ALSO
108  
109 =over 2
110  
111 =item L<Catalyst>
112  
113 =item L<Catalyst::Request::Upload>
114  
115 =item L<Image::Magick>
116  
117 =back
118  
119 =head1 BUGS
120  
121 Please report any bugs or feature requests to
122 C<bug-catalyst-plugin-upload-image-magick at rt.cpan.org>, or through the web interface at
123 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-Upload-Image-Magick>.
124 I will be notified, and then you'll automatically be notified of progress on
125 your bug as I make changes.
126  
127 =head1 SUPPORT
128  
129 You can find documentation for this module with the perldoc command.
130  
131 perldoc Catalyst::Plugin::Upload::Image::Magick
132  
133 You can also look for information at:
134  
135 =over 4
136  
137 =item * AnnoCPAN: Annotated CPAN documentation
138  
139 L<http://annocpan.org/dist/Catalyst-Plugin-Upload-Image-Magick>
140  
141 =item * CPAN Ratings
142  
143 L<http://cpanratings.perl.org/d/Catalyst-Plugin-Upload-Image-Magick>
144  
145 =item * RT: CPAN's request tracker
146  
147 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Upload-Image-Magick>
148  
149 =item * Search CPAN
150  
151 L<http://search.cpan.org/dist/Catalyst-Plugin-Upload-Image-Magick>
152  
153 =back
154  
155 =head1 Current Maintainer
156  
157 The current maintainer of this module is Adam Hopkins. Any questions or comments should be sent to him
158 at srchulo@cpan.org
159  
160 =head1 COPYRIGHT & LICENSE
161  
162 Copyright 2006 Toru Yamaguchi, all rights reserved.
163  
164 This program is free software; you can redistribute it and/or modify it
165 under the same terms as Perl itself.
166  
167 =cut
168  
169 1; # End of Catalyst::Plugin::Upload::Image::Magick