blib/lib/SWISH/Filters/ImageToMD5Xml.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 86.1% 56 / 65 CC 7 SCAR 10.0
CC
7
Cov
87%
filter
5.3
new
2.1
_parse_xml
2.0
CRAP 2.7
↑ Summary
1 package SWISH::Filters::ImageToMD5Xml;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use base 'SWISH::Filters::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 SWISH::Filters::ImageToMD5Xml - Adds MD5 information when filtering an image for SWISHE.
11  
12 =head1 VERSION
13  
14 Version 0.04
15  
16 =cut
17  
18 4 our $VERSION = '0.05';
19  
20 =head1 SYNOPSIS
21  
22 A L<SWISH::Filter> that takes an incoming image XML and applies a MD5 checksum
23 against the binary content of the image.
24  
25 The XML structure this filter expects includes an C<b64_data> element containing
26 the Base64 string representing the image. If that element (tag) is not found,
27 no filter is applied.
28  
29 =head1 METHODS
30  
31 =head2 new ( $class )
32  
33 Constructor.
34  
35 =cut
36  
37 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod documented
38 2 my ( $class ) = @_;
39  
40 2 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
41  
42 2 my $self = bless { }, $class;
43  
44 2 return $self->_init;
45 }
46  
47 2 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
48 2 my ( $self ) = @_;
49  
50 2 $self->use_modules(qw/MIME::Base64 Search::Tools::XML XML::Simple/);
51  
52 2 my @mimetypes = (
53 'application/xml'
54 );
55  
56 2 $self->{mimetypes} = \@mimetypes;
57  
58 2 return $self;
59 }
60  
61 2 ▶sub _parse_xml {
Subroutine _parse_xml: called CC=2 SCAR=7.1
62 2 my ( $self, $xml ) = @_;
63  
64 2 ▶ if ( $xml ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml) 2 0 2
65 2 return XMLin($xml);
66 }
67 }
68  
69 =head2 filter( $self, $doc )
70  
71 Generates XML meta data for indexing. If I<$doc> contains the C<b64_data> element (tag)
72 then a MD5 checksum string will be added to the XML and returned with a new root element C<image_data>.
73  
74 =cut
75  
76 2 ▶sub filter {
Subroutine filter: called CC=5 SCAR=16.6
Pod documented
77 2 my ( $self, $doc ) = @_;
78  
79 2 ▶ return if $doc->is_binary;
Branch: 1 branch
BranchTrueFalseTotal
if $doc->is_binary 0 2 2
80  
81 2 ▶ if ( my $xml = $doc->fetch_filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $xml = $doc->fetch_filename) 2 0 2
82 2 ▶ if ( my $ds = $self->_parse_xml($xml) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ds = $self->_parse_xml($xml)) 2 0 2
83 2 ▶ return unless exists $ds->{b64_data};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ds->{"b64_data"} 1 1 2
84 1 $ds->{md5} = md5_hex($ds->{b64_data});
85 1 my $xml = Search::Tools::XML->perl_to_xml($ds, { root => 'image_data' });
86 1 $doc->set_content_type('application/xml');
87 1 return ( \$xml );
88 }
89 }
90  
91 0 return;
92 }
93  
94  
95 =head1 AUTHOR
96  
97 Logan Bell, C<< <loganbell at gmail.com> >>
98  
99 =head1 BUGS
100  
101 Please report any bugs or feature requests to C<bug-swish-filters-imagetomd5xml at rt.cpan.org>, or through
102 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SWISH-Filters-ImageToMD5Xml>. I will be notified, and then you'll
103 automatically be notified of progress on your bug as I make changes.
104  
105  
106  
107  
108 =head1 SUPPORT
109  
110 You can find documentation for this module with the perldoc command.
111  
112 perldoc SWISH::Filters::ImageToMD5Xml
113  
114  
115 You can also look for information at:
116  
117 =over 4
118  
119 =item * RT: CPAN's request tracker (report bugs here)
120  
121 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SWISH-Filters-ImageToMD5Xml>
122  
123 =item * AnnoCPAN: Annotated CPAN documentation
124  
125 L<http://annocpan.org/dist/SWISH-Filters-ImageToMD5Xml>
126  
127 =item * CPAN Ratings
128  
129 L<http://cpanratings.perl.org/d/SWISH-Filters-ImageToMD5Xml>
130  
131 =item * Search CPAN
132  
133 L<http://search.cpan.org/dist/SWISH-Filters-ImageToMD5Xml/>
134  
135 =back
136  
137  
138 =head1 ACKNOWLEDGEMENTS
139  
140  
141 =head1 LICENSE AND COPYRIGHT
142  
143 Copyright 2011 Logan Bell.
144  
145 This program is free software; you can redistribute it and/or modify it
146 under the terms of either: the GNU General Public License as published
147 by the Free Software Foundation; or the Artistic License.
148  
149 See http://dev.perl.org/licenses/ for more information.
150  
151  
152 =cut
153  
154 4 1; # End of SWISH::Filters::ImageToMD5Xml
↑ Summary