README
1Class::Multimethods version 1.701
2 Class::Multimethods - Support multimethods and subroutine overloading in Perl
3
4SYNOPSIS
5
6 # ONLY WORKS UNDER 5.005 OR LATER (NEEDS qr//)
7
8 use 5.005;
9
10 # IMPORT THE multimethod DECLARATION SUB...
11
12 use Class::Multimethods;
13
14 # DECLARE VARIOUS MULTIMETHODS CALLED find...
15
16 # 1. DO THIS IF find IS CALLED WITH A Container REF AND A Query REF...
17
18 multimethod find => (Container, Query)
19 => sub { $_[0]->findquery($_[1]) };
20
21 # 2. DO THIS IF find IS CALLED WITH A Container REF AND A Sample REF...
22
23 multimethod find => (Container, Sample)
24 => sub { $_[0]->findlike($_[1]) };
25
26 # 3. DO THIS IF find IS CALLED WITH AN Index REF AND A Word REF...
27
28 multimethod find => (Index, Word)
29 => sub { $_[0]->lookup_word($_[1]) };
30
31 # 4. DO THIS IF find IS CALLED WITH AN Index REF AND A qr// PATTERN
32
33 multimethod find => (Index, Regexp)
34 => sub { $_[0]->lookup_rx($_[1]) };
35
36 # 5. DO THIS IF find IS CALLED WITH AN Index REF AND A NUMERIC SCALAR
37
38 multimethod find => (Index, '#')
39 => sub { $_[0]->lookup_elem($_[1]) };
40
41 # 6. DO THIS IF find IS CALLED WITH AN Index REF AND
42 # A NON-NUMERIC SCALAR
43
44 multimethod find => (Index, '$')
45 => sub { $_[0]->lookup_str($_[1]) };
46
47 # 7. DO THIS IF find IS CALLED WITH AN Index REF AND AN UNBLESSED
48 # ARRAY REF (NOTE THE RECURSIVE CALL TO THE find MULTIMETHOD)
49
50 multimethod find => (Index, ARRAY)
51 => sub { map { find($_[0],$_) } @{$_[1]} };
52
53 # SET UP SOME OBJECTS...
54
55 my $cntr = new Container ('./datafile');
56 my $indx = $cntr->get_index();
57
58 # ...AND SOME INHERITANCE...
59
60 @BadWord::ISA = qw( Word );
61 my $badword = new BadWord("fubar");
62
63 # ...AND EXERCISE THEM...
64
65 print find($cntr, new Query('cpan OR Perl')); # CALLS 1.
66 print find($cntr, new Example('by a committee')); # CALLS 2.
67
68 print find($indx, new Word('sugar')); # CALLS 3.
69 print find($indx, $badword); # CALLS 3.
70 print find($indx, qr/another brick in the Wall/); # CALLS 4.
71 print find($indx, 7); # CALLS 5.
72 print find($indx, 'But don't do that.'); # CALLS 6.
73 print find($indx, [1,"one"]); # CALLS 7,
74 # THEN 5,
75 # THEN 6.
76
77INSTALLATION
78
79 It's all pure Perl, so just put the .pm file in its appropriate
80 local Perl subdirectory.
81
82
83AUTHOR
84
85 Damian Conway (damian@cs.monash.edu.au)
86
87
88COPYRIGHT
89
90 Copyright (c) 1999-2000, Damian Conway. All Rights Reserved.
91 This module is free software. It may be used, redistributed
92 and/or modified under the same terms as Perl itself.
93