blib/lib/SWISH/Filters/ImageToMD5Xml.pm

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