File: README

package info (click to toggle)
libclass-multimethods-perl 1.70-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 156 kB
  • ctags: 93
  • sloc: perl: 855; makefile: 53
file content (120 lines) | stat: -rwxr-xr-x 3,965 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
==============================================================================
                Release of version 1.70 of Class::Multimethods
==============================================================================


NAME
	Class::Multimethods - Support multimethods and subroutine
			      overloading in Perl

SYNOPSIS

	# ONLY WORKS UNDER 5.005 OR LATER (NEEDS qr//)

	      use 5.005;

        # IMPORT THE multimethod DECLARATION SUB...

              use Class::Multimethods;

        # DECLARE VARIOUS MULTIMETHODS CALLED find...

        # 1. DO THIS IF find IS CALLED WITH A Container REF AND A Query REF...

              multimethod find => (Container, Query)
                               => sub { $_[0]->findquery($_[1]) };

        # 2. DO THIS IF find IS CALLED WITH A Container REF AND A Sample REF...

              multimethod find => (Container, Sample)
                               => sub { $_[0]->findlike($_[1]) };

        # 3. DO THIS IF find IS CALLED WITH AN Index REF AND A Word REF...

              multimethod find => (Index, Word)
                               => sub { $_[0]->lookup_word($_[1]) };

        # 4. DO THIS IF find IS CALLED WITH AN Index REF AND A qr// PATTERN

              multimethod find => (Index, Regexp)
                               => sub { $_[0]->lookup_rx($_[1]) };

        # 5. DO THIS IF find IS CALLED WITH AN Index REF AND A NUMERIC SCALAR

              multimethod find => (Index, '#')
                               => sub { $_[0]->lookup_elem($_[1]) };

        # 6. DO THIS IF find IS CALLED WITH AN Index REF AND
	#    A NON-NUMERIC SCALAR

              multimethod find => (Index, '$')
                               => sub { $_[0]->lookup_str($_[1]) };

        # 7. DO THIS IF find IS CALLED WITH AN Index REF AND AN UNBLESSED
	#    ARRAY REF (NOTE THE RECURSIVE CALL TO THE find MULTIMETHOD)

              multimethod find => (Index, ARRAY)
                               => sub { map { find($_[0],$_) } @{$_[1]} };

        # SET UP SOME OBJECTS...

              my $cntr = new Container ('./datafile');
              my $indx = $cntr->get_index();

        # ...AND SOME INHERITANCE...

              @BadWord::ISA = qw( Word );
              my $badword = new BadWord("fubar");

        # ...AND EXERCISE THEM...

              print find($cntr, new Query('cpan OR Perl'));           # CALLS 1.
              print find($cntr, new Example('by a committee'));       # CALLS 2.

              print find($indx, new Word('sugar'));                   # CALLS 3.
              print find($indx, $badword);                            # CALLS 3.
              print find($indx, qr/another brick in the Wall/);       # CALLS 4.
              print find($indx, 7);                                   # CALLS 5.
              print find($indx, 'But don't do that.');                # CALLS 6.
              print find($indx, [1,"one"]);                           # CALLS 7,
                                                                      # THEN 5,
								      # THEN 6.

INSTALLATION

    It's all pure Perl, so just put the .pm file in its appropriate
    local Perl subdirectory.


AUTHOR

    Damian Conway (damian@cs.monash.edu.au)


COPYRIGHT

       Copyright (c) 1999-2000, Damian Conway. All Rights Reserved.
     This module is free software. It may be used, redistributed
         and/or modified under the same terms as Perl itself.


==============================================================================

CHANGES IN VERSION 1.70


	- moved .pod file to installable directory (/lib)

	- Added TPC3 paper as tutorial.html (thanks Tom)


==============================================================================

AVAILABILITY

Class::Multimethods has been uploaded to the CPAN
and is also available from:

	http://www.csse.monash.edu.au/~damian/CPAN/Class-Multimethods.tar.gz

==============================================================================