blib/lib/File/Find/Rule/DIZ.pm

filter: Statementstmt 100% 34 / 34 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 94.3% 50 / 53 CC 6 SCAR 9.9
CC
6
Cov
95%
__ANON__
5.0
diz
2.0
BEGIN
1.0
CRAP 2.7
↑ Summary
1 package File::Find::Rule::DIZ;
2  
3 =head1 NAME
4  
5 File::Find::Rule::DIZ - Rule to match the contents of a FILE_ID.DIZ
6  
7 =head1 SYNOPSIS
8  
9 use File::Find::Rule::DIZ;
10  
11 my @files = find( diz => { text => qr/stuff and things/ }, in => '/archives' );
12  
13 =head1 DESCRIPTION
14  
15 This module will search through a ZIP archive, specifically the contents of the FILE_ID.DIZ
16 file in the archive.
17  
18 =cut
19  
20 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use base qw( File::Find::Rule );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use vars qw( @EXPORT $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 3 @EXPORT = @File::Find::Rule::EXPORT;
28 3 $VERSION = '0.06';
29  
30 3 ▶use Archive::Zip;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 =head1 METHODS
33  
34 =head2 diz( %options )
35  
36 my @files = find( diz => { text => qr/stuff and things/ }, in => '/archives' );
37  
38 For now, all you can do is search the text using a regex. Yehaw.
39  
40 =cut
41  
42 2 ▶sub File::Find::Rule::diz {
Subroutine diz: called CC=2 SCAR=6.9
Pod undocumented
43 2 my $self = shift->_force_object;
44  
45 # Procedural interface allows passing arguments as a hashref.
46 2 ▶ my %criteria = UNIVERSAL::isa( $_[ 0 ], 'HASH' ) ? %{ $_[ 0 ] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], 'HASH') ? : 2 0 2
47  
48 6 ▶ $self->exec( sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
49 6 my $file = shift;
50  
51 # is it a binary file?
52 6 ▶ return unless -B $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -B $file 2 4 6
53  
54 # is it a zip file?
55 4 my $zip = Archive::Zip->new( $file );
56 4 ▶ return unless $zip;
Branch: 1 branch
BranchTrueFalseTotal
unless $zip 2 2 4
57  
58 # does it contain a file_id.diz?
59 2 my $member = $zip->memberNamed( 'FILE_ID.DIZ' );
60 2 ▶ return unless $member;
Branch: 1 branch
BranchTrueFalseTotal
unless $member 0 2 2
61  
62 # does it match the desired data?
63 2 my $diz = $member->contents;
64 2 ▶ return unless $diz =~ $criteria{ text };
Branch: 1 branch
BranchTrueFalseTotal
unless $diz =~ /$criteria{"text"}/ 1 1 2
65  
66 1 return 1;
67 2 } );
68 }
69  
70 =head1 AUTHOR
71  
72 =over 4
73  
74 =item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>
75  
76 =back
77  
78 =head1 COPYRIGHT AND LICENSE
79  
80 Copyright 2007 by Brian Cassidy
81  
82 This library is free software; you can redistribute it and/or modify
83 it under the same terms as Perl itself.
84  
85 =head1 SEE ALSO
86  
87 =over 4
88  
89 =item * File::Find::Rule
90  
91 =item * File::Find::Rule::MP3Info
92  
93 =back
94  
95 =cut
96  
97 3 1;
↑ Summary