Sub-MultiMethod
view release on metacpan or search on metacpan
multi stringify => [ Num ] => sub ( $n ) {
return $n;
};
multi stringify => [ ArrayRef ] => sub ( $arr ) {
return sprintf(
q<[%s]>,
join( q<,>, map( stringify($_), @$arr ) )
);
};
multi stringify => [ HashRef ] => sub ( $hash ) {
return sprintf(
q<{%s}>,
join(
q<,>,
map sprintf(
q<%s:%s>,
stringify_str($_),
stringify( $hash->{$_} )
), sort keys %$hash,
)
);
};
}
say My::JSON::stringify( {
foo => 123,
bar => [ 1, 2, 3 ],
baz => \1,
quux => { xyzzy => 666 },
} );
BUGS
Please report any bugs to
<http://rt.cpan.org/Dist/Display.html?Queue=Sub-MultiMethod>.
SEE ALSO
Multi::Dispatch - probably almost as nice an implementation as
Sub::MultiMethod. It correctly handles inheritance, does a good job of
dispatching to the best candidate, etc. It's even significantly faster
than Sub::MultiMethod. On the downsides, it doesn't handle roles or
coercions.
Class::Multimethods - uses Perl classes and ref types to dispatch. No
syntax hacks but the fairly nice syntax shown in the pod relies on `use
strict` being switched off! Need to quote a few more things otherwise.
Class::Multimethods::Pure - similar to Class::Multimethods but with a more
complex type system and a more complex dispatch method.
Logic - a full declarative programming framework. Overkill if all you want
is multimethods. Uses source filters.
Dios - object oriented programming framework including multimethods.
Includes a full type system and Keyword::Declare-based syntax. Pretty
sensible dispatch technique which is almost identical to Sub::MultiMethod.
Much much slower though, at both compile time and runtime.
MooseX::MultiMethods - uses Moose type system and Devel::Declare-based
syntax. Not entirely sure what the dispatching method is.
Kavorka - I wrote this, so I'm allowed to be critical. Type::Tiny-based
type system. Very naive dispatching; just dispatches to the first declared
candidate that can handle it rather than trying to find the "best".
Sub::Multi::Tiny - uses Perl attributes to declare candidates to be
dispatched to. Pluggable dispatching, but by default uses argument count.
Sub::Multi - syntax wrapper around Class::Multimethods::Pure?
Sub::SmartMatch - kind of abandoned and smartmatch is generally seen as
teh evilz these days.
AUTHOR
Toby Inkster <tobyink@cpan.org>.
COPYRIGHT AND LICENCE
This software is copyright (c) 2020-2022 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.
( run in 1.248 second using v1.01-cache-2.11-cpan-e1769b4cff6 )