1 | package Sort::Key::Register;
|
---|
2 |
|
---|
3 | our $VERSION = '1.30';
|
---|
4 |
|
---|
5 | use warnings;
|
---|
6 | use strict;
|
---|
7 |
|
---|
8 | use Sort::Key;
|
---|
9 |
|
---|
10 | sub import {
|
---|
11 | my $class = shift;
|
---|
12 | my $name = shift;
|
---|
13 | if (@_ == 1) {
|
---|
14 | Sort::Key::Types::register_type($name, undef, @_);
|
---|
15 | }
|
---|
16 | else {
|
---|
17 | Sort::Key::Types::register_type($name, @_);
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | 1;
|
---|
22 | __END__
|
---|
23 |
|
---|
24 | =head1 NAME
|
---|
25 |
|
---|
26 | Sort::Key::Register - tell Sort::Key how to sort new data types.
|
---|
27 |
|
---|
28 | =head1 SYNOPSYS
|
---|
29 |
|
---|
30 | use Sort::Key::Register Person =>
|
---|
31 | sub { $_->surname, $_->name },
|
---|
32 | qw(string string);
|
---|
33 |
|
---|
34 | use Sort::Key::Register 'Color::Component' => 'integer';
|
---|
35 |
|
---|
36 | use Sort::Key::Register Color =>
|
---|
37 | sub { $_->R, $_->G, $_->B },
|
---|
38 | ('Color::Component') x 3;
|
---|
39 |
|
---|
40 |
|
---|
41 | =head1 DESCRIPTION
|
---|
42 |
|
---|
43 | Sort::Key::Register allows to register new data types with Sort::Key
|
---|
44 | so that they can be sorted as natively supported ones.
|
---|
45 |
|
---|
46 | It works as a pragma module and doesn't export any function, all its
|
---|
47 | functionality is provided via C<use>:
|
---|
48 |
|
---|
49 | use Sort::Key::Register ...
|
---|
50 |
|
---|
51 | To avoid collisions between modules registering types with the same
|
---|
52 | name, you should qualify them with the package name.
|
---|
53 |
|
---|
54 | use Sort::Key::Register 'MyPkg::foo' => sub { $_ }, '-int';
|
---|
55 |
|
---|
56 | # or using __PACKAGE__:
|
---|
57 | use Sort::Key::Register __PACKAGE__, sub { $_ }, '-int';
|
---|
58 |
|
---|
59 | =head2 USAGE
|
---|
60 |
|
---|
61 | =over 4
|
---|
62 |
|
---|
63 | =item use Sort::Key::Register $name => \&multikeygen, @keytypes;
|
---|
64 |
|
---|
65 | registers type C<$name>.
|
---|
66 |
|
---|
67 | C<&multikeygen> is the multikey extraction function for the type and
|
---|
68 | C<@keytypes> are the types of the extracted keys.
|
---|
69 |
|
---|
70 | =item use Sort::Key::Register $name => $keytype;
|
---|
71 |
|
---|
72 | this 'use' is useful for simple types that are sorted as another type
|
---|
73 | already registered, maybe changing the direction of the sort
|
---|
74 | (ascending or descending).
|
---|
75 |
|
---|
76 | =back
|
---|
77 |
|
---|
78 | =head1 SEE ALSO
|
---|
79 |
|
---|
80 | L<Sort::Key>, L<Sort::Key::Maker>.
|
---|
81 |
|
---|
82 | =head1 AUTHOR
|
---|
83 |
|
---|
84 | Salvador FandiE<ntilde>o, E<lt>[email protected]<gt>
|
---|
85 |
|
---|
86 | =head1 COPYRIGHT AND LICENSE
|
---|
87 |
|
---|
88 | Copyright (C) 2005 by Salvador FandiE<ntilde>o
|
---|
89 |
|
---|
90 | This library is free software; you can redistribute it and/or modify
|
---|
91 | it under the same terms as Perl itself, either Perl version 5.8.4 or,
|
---|
92 | at your option, any later version of Perl 5 you may have available.
|
---|
93 |
|
---|
94 | =cut
|
---|