File Coverage

blib/lib/File/Find/Rule/ImageSize.pm
Criterion Covered Total %
statement 34 34 100.0
branch 4 4 100.0
condition n/a
subroutine 10 10 100.0
pod 0 2 0.0
total 48 50 96.0


line stmt bran cond sub pod time code
1             # $Id: ImageSize.pm 875 2002-10-29 11:05:17Z richardc $
2             package File::Find::Rule::ImageSize;
3 1     1   23384 use strict;
  1         3  
  1         33  
4              
5 1     1   826 use File::Find::Rule;
  1         11408  
  1         11  
6 1     1   55 use base qw( File::Find::Rule );
  1         8  
  1         143  
7 1     1   5 use vars qw/$VERSION @EXPORT/;
  1         2  
  1         81  
8             $VERSION = '0.03';
9             @EXPORT = @File::Find::Rule::EXPORT;
10              
11 1     1   4 use Number::Compare;
  1         2  
  1         19  
12 1     1   1220 use Image::Size qw( imgsize );
  1         7268  
  1         354  
13              
14             my $dimension;
15 2     2 0 1586 sub File::Find::Rule::image_x { $dimension = 'x'; &_match_dimension }
  2         8  
16 2     2 0 2508 sub File::Find::Rule::image_y { $dimension = 'y'; &_match_dimension }
  2         10  
17              
18             sub _match_dimension {
19 4     4   18 my $self = shift()->_force_object;
20 4         112 my $axis = $dimension;
21 4         11 my @rules = map { Number::Compare->new($_) } @_;
  4         51  
22             $self->exec( sub {
23 12     12   3963 my %h; @h{'x', 'y'} = imgsize($_);
  12         55  
24 12         90672 my $val = $h{ $axis };
25 12 100       709 return unless defined $val;
26 4 100       40 for (@rules) { return 1 if $_->($val) }
  4         429  
27 2         78 return;
28 4         779 } );
29             }
30              
31             1;
32              
33             =head1 NAME
34              
35             File::Find::Rule::ImageSize - rules for matching image dimensions
36              
37             =head1 SYNOPSIS
38              
39             use File::Find::Rule::ImageSize;
40             # find images bigger than 20x20
41             my @images = find( file => image_x => '>20', image_y => '>20', in => '.' );
42              
43             =head1 DESCRIPTION
44              
45             File::Find::Rule::ImageSize interfaces Image::Size to File::Find::Rule
46             enabling you to find files based upon their dimensions.
47             Number::Compare is used so that the sizes may be relative values.
48              
49             =head2 ->image_x( @sizes )
50             =head2 ->image_y( @sizes )
51              
52             Match only things with their dimensions constrained by @sizes. The
53             specification can be a relative, as implemented by L.
54              
55             =head1 AUTHOR
56              
57             Richard Clamp , from an idea by Mark Fowler.
58              
59             =head1 COPYRIGHT
60              
61             Copyright (C) 2002 Richard Clamp. All Rights Reserved.
62              
63             This module is free software; you can redistribute it and/or modify it
64             under the same terms as Perl itself.
65              
66             =head1 SEE ALSO
67              
68             L, L, L
69              
70             =cut