Sort::Key::Types(3pm)

Sort::Key::Types3pm

Usage

  use Sort::Key::Types qw(register_type);
  register_type(Color => sub { $_->R, $_->G, $_->B }, qw(int, int, int));
  # you better
  # use Sort::Key::Register ...

Sort::Key::Types - handle Sort::Key data types

Overview

The Sort::Key family of modules can be extended to support new key types using this module (or the more friendly Sort::Key::Register).

Functions

The following functions are provided:

Sort::Key::register_type($name, \&gensubkeys, @subkeystypes)

registers a new datatype named $name defining how to convert it to a multi-key.

&gensubkeys should convert the object of type $name passed on $_ to a list of values composing the multi-key.

@subkeystypes is the list of types for the generated multi-keys.

For instance:

  Sort::Key::Types::register_type
                 'Person',
                 sub { $_->surname,
                       $_->name,
                       $_->middlename },
                 qw(str str str);
  Sort::Key::Types::register_type
                 'Color',
                 sub { $_->R, $_->G, $_->B },
                 qw(int int int);

Once a datatype has been registered it can be used in the same way as types supported natively, even for defining new types, i.e.:

  Sort::Key::Types::register_type
                 'Family',
                 sub { $_->father, $_->mother },
                 qw(Person Person);

Releases

8 releases since Debian 7 (Wheezy); the text changed 7 times.

  1. 7
  2. 8
  3. 9
  4. 10
  5. 11
  6. 12
  7. 13
  8. Arch

From perl-sort-key 1.33-16 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.