MAN page from OpenSuSE perl-File-Find-Rule-0.350.0-2.5.noarch.rpm
File::Find::Rule::Extending
Section: User Contributed Perl Documentation (3)
Updated: 2025-06-11
Index NAME
File::Find::Rule::Extending - the mini-guide to extending File::Find::Rule
SYNOPSIS
package File::Find::Rule::Random; use strict; # take useful things from File::Find::Rule use base 'File::Find::Rule'; # and force our crack into the main namespace sub File::Find::Rule::random () { my $self = shift()->_force_object; $self->exec( sub { rand > 0.5 } ); } 1; DESCRIPTION
File::Find::Rule went down so well with the buying public thateveryone wanted to add extra features. With the 0.07 release thisbecame a possibility, using the following conventions.
Declare your package
package File::Find::Rule::Random; use strict;
Inherit methods from File::Find::Rule
# take useful things from File::Find::Rule use base 'File::Find::Rule';
Force your madness into the main package
# and force our crack into the main namespace sub File::Find::Rule::random () { my $self = shift()->_force_object; $self->exec( sub { rand > 0.5 } ); }Yes, we're being very cavalier here and defining things into the mainFile::Find::Rule namespace. This is due to lack of imaginiation on mypart - I simply can't find a way for the functional and oo interfaceto work without doing this or some kind of inheritance, andinheritance stops you using two File::Find::Rule::Foo modulestogether.
For this reason try and pick distinct names for your extensions. Ifthis becomes a problem then I may institute a semi-official registryof taken names.
Taking no arguments.
Note the null prototype on random. This is a cheat for the proceduralinterface to know that your sub takes no arguments, and so allows thisto happen:
find( random => in => '.' );
If you hadn't declared "random" with a null prototype it would haveconsumed "in" as a parameter to it, then got all confused as itdoesn't know about a '.' rule.
AUTHOR
Richard Clamp <richardcAATTunixbeard.net>
COPYRIGHT
Copyright (C) 2002 Richard Clamp. All Rights Reserved.
This module is free software; you can redistribute it and/or modify itunder the same terms as Perl itself.
SEE ALSO
File::Find::Rule
File::Find::Rule::MMagic was the first extension module, so maybecheck that out.
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- Declare your package
- Inherit methods from File::Find::Rule
- Taking no arguments.
- AUTHOR
- COPYRIGHT
- SEE ALSO
This document was created byman2html,using the manual pages.