source: gs2-extensions/parallel-building/trunk/src/perllib/cpan/Sort/Key/Register.pm@ 27037

Last change on this file since 27037 was 27037, checked in by jmt12, 11 years ago

Allow natural sorting in Perl

File size: 2.0 KB
Line 
1package Sort::Key::Register;
2
3our $VERSION = '1.30';
4
5use warnings;
6use strict;
7
8use Sort::Key;
9
10sub 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
211;
22__END__
23
24=head1 NAME
25
26Sort::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
43Sort::Key::Register allows to register new data types with Sort::Key
44so that they can be sorted as natively supported ones.
45
46It works as a pragma module and doesn't export any function, all its
47functionality is provided via C<use>:
48
49 use Sort::Key::Register ...
50
51To avoid collisions between modules registering types with the same
52name, 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
65registers type C<$name>.
66
67C<&multikeygen> is the multikey extraction function for the type and
68C<@keytypes> are the types of the extracted keys.
69
70=item use Sort::Key::Register $name => $keytype;
71
72this 'use' is useful for simple types that are sorted as another type
73already registered, maybe changing the direction of the sort
74(ascending or descending).
75
76=back
77
78=head1 SEE ALSO
79
80L<Sort::Key>, L<Sort::Key::Maker>.
81
82=head1 AUTHOR
83
84Salvador FandiE<ntilde>o, E<lt>[email protected]<gt>
85
86=head1 COPYRIGHT AND LICENSE
87
88Copyright (C) 2005 by Salvador FandiE<ntilde>o
89
90This library is free software; you can redistribute it and/or modify
91it under the same terms as Perl itself, either Perl version 5.8.4 or,
92at your option, any later version of Perl 5 you may have available.
93
94=cut
Note: See TracBrowser for help on using the repository browser.