1File::Find::Rule::ExtenUdsienrg(C3o)ntributed Perl DocumFeinltea:t:iFoinnd::Rule::Extending(3)
2
3
4

NAME

6       File::Find::Rule::Extending - the mini-guide to extending
7       File::Find::Rule
8

SYNOPSIS

10        package File::Find::Rule::Random;
11        use strict;
12
13        # take useful things from File::Find::Rule
14        use base 'File::Find::Rule';
15
16        # and force our crack into the main namespace
17        sub File::Find::Rule::random () {
18            my $self = shift()->_force_object;
19            $self->exec( sub { rand > 0.5 } );
20        }
21
22        1;
23

DESCRIPTION

25       File::Find::Rule went down so well with the buying public that everyone
26       wanted to add extra features.  With the 0.07 release this became a pos‐
27       sibility, using the following conventions.
28
29       Declare your package
30
31        package File::Find::Rule::Random;
32        use strict;
33
34       Inherit methods from File::Find::Rule
35
36        # take useful things from File::Find::Rule
37        use base 'File::Find::Rule';
38
39       Force your madness into the main package
40
41        # and force our crack into the main namespace
42        sub File::Find::Rule::random () {
43            my $self = shift()->_force_object;
44            $self->exec( sub { rand > 0.5 } );
45        }
46
47       Yes, we're being very cavalier here and defining things into the main
48       File::Find::Rule namespace.  This is due to lack of imaginiation on my
49       part - I simply can't find a way for the functional and oo interface to
50       work without doing this or some kind of inheritance, and inheritance
51       stops you using two File::Find::Rule::Foo modules together.
52
53       For this reason try and pick distinct names for your extensions.  If
54       this becomes a problem then I may institute a semi-official registry of
55       taken names.
56
57       Taking no arguments.
58
59       Note the null prototype on random.  This is a cheat for the procedural
60       interface to know that your sub takes no arguments, and so allows this
61       to happen:
62
63        find( random => in => '.' );
64
65       If you hadn't declared "random" with a null prototype it would have
66       consumed "in" as a parameter to it, then got all confused as it doesn't
67       know about a '.' rule.
68

AUTHOR

70       Richard Clamp <richardc@unixbeard.net>
71
73       Copyright (C) 2002 Richard Clamp.  All Rights Reserved.
74
75       This module is free software; you can redistribute it and/or modify it
76       under the same terms as Perl itself.
77

SEE ALSO

79       File::Find::Rule
80
81       File::Find::Rule::MMagic was the first extension module, so maybe check
82       that out.
83
84
85
86perl v5.8.8                       2006-06-01    File::Find::Rule::Extending(3)
Impressum