File Coverage

blib/lib/Catalyst/View/Image/Empty.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Catalyst::View::Image::Empty;
2              
3 1     1   21092 use strict;
  1         2  
  1         65  
4 1     1   5 use warnings;
  1         2  
  1         26  
5              
6 1     1   418 use Moose;
  0            
  0            
7              
8             extends 'Catalyst::View';
9              
10             use Image::Empty;
11              
12             has format => ( is => 'ro', isa => 'Str', default => 'gif' );
13             has filename => ( is => 'ro', isa => 'Str' );
14              
15             =head1 NAME
16              
17             Catalyst::View::Image::Empty - View to return a 1x1 empty GIF or PNG, for building tracking URLs.
18              
19             =head1 VERSION
20              
21             Version 0.06
22              
23             =cut
24              
25             our $VERSION = '0.06';
26              
27             $VERSION = eval $VERSION;
28              
29             =head1 SYNOPSIS
30              
31             =head3 Create View
32              
33             script/myapp_create.pl view My::Image::Empty Image::Empty
34              
35             =head3 In Your Controller
36              
37             sub tracker :Local
38             {
39             my ( $self, $c ) = @_;
40            
41             $c->detach('View::My::Image::Empty');
42             }
43              
44             =cut
45              
46             =head1 DESCRIPTION
47              
48             Catalyst::View::Image::Empty is a view that returns a 1x1 empty GIF or PNG, for building tracking URLs.
49              
50             GIF is default.
51            
52             You can switch to PNG by specifying the C<format> in the config.
53              
54             package MyApp::View::Image::Empty;
55            
56             use strict;
57             use warnings;
58            
59             use base 'Catalyst::View::Image::Empty';
60            
61             __PACKAGE__->config(
62             format => 'png',
63             );
64              
65             C<filename> is another config option you can change, the default filename you would see if you "Save Page As..." in a browser.
66              
67             =cut
68              
69             sub process
70             {
71             my ( $self, $c ) = @_;
72              
73             my $format = $self->format;
74            
75             my $empty = Image::Empty->$format;
76            
77             $empty->filename( $self->filename ) if $self->filename;
78            
79             $c->response->content_type( $empty->type );
80             $c->response->content_length( $empty->length );
81             $c->response->header( 'Content-Disposition' => $empty->disposition . '; filename="' . $empty->filename . '"' );
82              
83             $c->response->body( $empty->content );
84             }
85              
86             =head1 SEE ALSO
87              
88             L<Image::Empty>
89              
90             =head1 AUTHOR
91              
92             Rob Brown, C<< <rob at intelcompute.com> >>
93              
94             =head1 BUGS
95              
96             Please report any bugs or feature requests to C<bug-catalyst-view-image-empty at rt.cpan.org>, or through
97             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-View-Image-Empty>. I will be notified, and then you will
98             automatically be notified of progress on your bug as I make changes.
99              
100             =head1 SUPPORT
101              
102             You can find documentation for this module with the perldoc command.
103              
104             perldoc Catalyst::View::Image::Empty
105              
106              
107             You can also look for information at:
108              
109             =over 4
110              
111             =item * RT: CPAN's request tracker (report bugs here)
112              
113             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-View-Image-Empty>
114              
115             =item * AnnoCPAN: Annotated CPAN documentation
116              
117             L<http://annocpan.org/dist/Catalyst-View-Image-Empty>
118              
119             =item * CPAN Ratings
120              
121             L<http://cpanratings.perl.org/d/Catalyst-View-Image-Empty>
122              
123             =item * Search CPAN
124              
125             L<http://search.cpan.org/dist/Catalyst-View-Image-Empty/>
126              
127             =back
128              
129             =head1 LICENSE AND COPYRIGHT
130              
131             Copyright 2012 Rob Brown.
132              
133             This program is free software; you can redistribute it and/or modify it
134             under the terms of either: the GNU General Public License as published
135             by the Free Software Foundation; or the Artistic License.
136              
137             See http://dev.perl.org/licenses/ for more information.
138              
139             =cut
140              
141             1;
142