File::Find::Rule::MMagic - rule to match on mime types


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

Index


Code Index:

NAME

Top

File::Find::Rule::MMagic - rule to match on mime types

SYNOPSIS

Top

 use File::Find::Rule::MMagic;
 my @images = find( file => magic => 'image/*', in => '.' );

DESCRIPTION

Top

File::Find::Rule::MMagic interfaces File::MMagic to File::Find::Rule enabling you to find files based upon their mime type. Text::Glob is used so that the patter may be a simple globbing pattern.

->magic( @patterns )

Match only things with the mime types specified by @patterns. The specification can be a glob pattern, as provided by Text::Glob.

AUTHOR

Top

Richard Clamp <richardc@unixbeard.net>, from an idea by Mark Fowler.

COPYRIGHT

Top

SEE ALSO

Top

File::Find::Rule, Text::Glob, File::MMagic


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

# $Id: MMagic.pm 877 2002-10-29 11:16:05Z richardc $
package File::Find::Rule::MMagic;
use strict;

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

use File::MMagic;
use Text::Glob qw(glob_to_regex);

sub File::Find::Rule::magic {
    my $self = shift()->_force_object;
    my @patterns = map { ref $_ ? $_ : glob_to_regex $_ } @_;
    my $mm = new File::MMagic;
    $self->exec( sub {
                     my $type = $mm->checktype_filename($_);
                     for (@patterns) { return 1 if $type =~ m/$_/ }
                     return;
                 } );
}

1;
__END__