The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Smart::Dispatch::Table - a dispatch table

DESCRIPTION

Smart::Dispatch::Table is a Moose class. (Well, Moo actually, but close enough.)

Constructors

  • new(%attributes)

    Create a new dispatch table.

  • make_combined($table1, $table2, ...)

    Combine existing tables into a new one.

Attributes

  • match_list

    is 'rw', isa 'ArrayRef[Smart::Dispatch::Match]'.

Methods

  • exists($value, $include_failovers)

    Searches for a Smart::Dispatch::Match that matches $value. Ignores failover matches, unless optional argument $include_failovers is true. Returns Smart::Dispatch::Match if it finds a match; returns nothing otherwise.

    TL;DR: checks if value $value can be dispatched.

  • action($value, @additional)

    Calls exists with $include_failovers set to true, then, if there is a result, calls conduct_dispatch($value, @additional) on that result.

    TL;DR: dispatches value $value.

  • conditional_matches

    Returns a list of conditional matches. (Smart::Dispatch::Match objects.)

  • unconditional_matches

    Returns a list of unconditional matches. (Smart::Dispatch::Match objects.)

    Should only ever be zero or one items in the list.

  • all_matches

    Returns the list which is the union of the above two lists.

  • append(@things)

    Each thing must be a Smart::Dispatch::Table or a Smart::Dispatch::Match.

    Handles conflicts between unconditional matches automatically.

  • prepend(@things)

    Each thing must be a Smart::Dispatch::Table or a Smart::Dispatch::Match.

    Handles conflicts between unconditional matches automatically.

  • validate_match_list

    Checks that match_list looks OK (a maximum of unconditional match; checks that all conditional matches preceed unconditional matches).

    This is done automatically after construction, prepending and appending, but if you've manipulated the match_list manually, it's good practice to all this method to check you've not broken it.

Overloads

Smart::Dispatch::Table overloads various operations. (See overload.)

  • code derefernce &{} - funky stuff with action.

  • concatenation . - funky stuff with make_combined.

  • addition + - funky stuff with make_combined.

  • concatenation assignment .= - append.

  • addition assignment += - prepend.

  • smart match ~~ - exists (with $ignore_failover false).

BUGS

Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Smart-Dispatch.

SEE ALSO

Smart::Dispatch.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2012 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.