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

AUTHOR

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

SEE ALSO

76       File::Find::Rule
77
78       File::Find::Rule::MMagic was the first extension module, so maybe check
79       that out.
80
81
82
83perl v5.30.0                      2019-07-26    File::Find::Rule::Extending(3)
Impressum