blib/lib/SWISH/Filters/ImageToMD5Xml.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 84.6% 55 / 65 SCAR 19.7
CC
7
Cov
85%
filter
5.5
new
2.1
_parse_xml
2.0
CRAP 7.2
↑ Summary
1 package SWISH::Filters::ImageToMD5Xml;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base 'SWISH::Filters::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Digest::MD5 qw(md5);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶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 3 our $VERSION = '0.04';
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 sub new {
38 1 ▶ my ( $class ) = @_;
Subroutine new: called CC=2 SCAR=7.4
Pod documented
39  
40 1 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
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 1 my $self = bless { }, $class;
43  
44 1 return $self->_init;
45 }
46  
47 sub _init {
48 1 ▶ my ( $self ) = @_;
Subroutine _init: called CC=1 SCAR=0.0
49  
50 1 $self->use_modules(qw/MIME::Base64 Search::Tools::XML XML::Simple/);
51  
52 1 my @mimetypes = (
53 'application/xml'
54 );
55  
56 1 $self->{mimetypes} = \@mimetypes;
57  
58 1 return $self;
59 }
60  
61 sub _parse_xml {
62 1 ▶ my ( $self, $xml ) = @_;
Subroutine _parse_xml: called CC=2 SCAR=7.1
63  
64 1 ▶ if ( $xml ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml) 1 0 1
65 1 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 sub filter {
77 1 ▶ my ( $self, $doc ) = @_;
Subroutine filter: called CC=5 SCAR=17.1
Pod documented
78  
79 1 ▶ return if $doc->is_binary;
Branch: 1 branch
BranchTrueFalseTotal
if $doc->is_binary 0 1 1
80  
81 1 ▶ if ( my $xml = $doc->fetch_filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $xml = $doc->fetch_filename) 1 0 1
82 1 ▶ if ( my $ds = $self->_parse_xml($xml) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ds = $self->_parse_xml($xml)) 1 0 1
83 1 ▶ return unless exists $ds->{b64_data};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ds->{"b64_data"} 0 1 1
84 1 $ds->{md5} = md5($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 3 1; # End of SWISH::Filters::ImageToMD5Xml
↑ Summary