File::Find::Rule::DIZ - Rule to match the contents of a FILE_ID.DIZ


File-Find-Rule-DIZ documentation Contained in the File-Find-Rule-DIZ distribution.

Index


Code Index:

NAME

Top

File::Find::Rule::DIZ - Rule to match the contents of a FILE_ID.DIZ

SYNOPSIS

Top

    use File::Find::Rule::DIZ;

    my @files = find( diz => { text => qr/stuff and things/ }, in => '/archives' );

DESCRIPTION

Top

This module will search through a ZIP archive, specifically the contents of the FILE_ID.DIZ file in the archive.

METHODS

Top

diz( %options )

    my @files = find( diz => { text => qr/stuff and things/ }, in => '/archives' );

For now, all you can do is search the text using a regex. Yehaw.

AUTHOR

Top

* Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top

SEE ALSO

Top

* File::Find::Rule
* File::Find::Rule::MP3Info

File-Find-Rule-DIZ documentation Contained in the File-Find-Rule-DIZ distribution.
package File::Find::Rule::DIZ;

use strict;
use warnings;

use File::Find::Rule;
use base qw( File::Find::Rule );
use vars qw( @EXPORT $VERSION );

@EXPORT  = @File::Find::Rule::EXPORT;
$VERSION = '0.06';

use Archive::Zip;

sub File::Find::Rule::diz {
    my $self = shift->_force_object;

    # Procedural interface allows passing arguments as a hashref.
    my %criteria = UNIVERSAL::isa( $_[ 0 ], 'HASH' ) ? %{ $_[ 0 ] } : @_;

    $self->exec( sub {
        my $file = shift;

        # is it a binary file?
        return unless -B $file;

        # is it a zip file?
        my $zip = Archive::Zip->new( $file );
        return unless $zip;

        # does it contain a file_id.diz?
        my $member = $zip->memberNamed( 'FILE_ID.DIZ' );
        return unless $member;

        # does it match the desired data?
        my $diz = $member->contents;
        return unless $diz =~ $criteria{ text };

        return 1;
    } );
}

1;