Sub-MultiMethod
view release on metacpan or search on metacpan
lib/Sub/MultiMethod.pm view on Meta::CPAN
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 },
} );
=head1 BUGS
Please report any bugs to
L<http://rt.cpan.org/Dist/Display.html?Queue=Sub-MultiMethod>.
=head1 SEE ALSO
L<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.
L<Class::Multimethods> - uses Perl classes and ref types to dispatch.
No syntax hacks but the fairly nice syntax shown in the pod relies on
C<use strict> being switched off! Need to quote a few more things otherwise.
L<Class::Multimethods::Pure> - similar to Class::Multimethods but with
a more complex type system and a more complex dispatch method.
L<Logic> - a full declarative programming framework. Overkill if all
you want is multimethods. Uses source filters.
L<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.
L<MooseX::MultiMethods> - uses Moose type system and Devel::Declare-based
syntax. Not entirely sure what the dispatching method is.
L<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".
L<Sub::Multi::Tiny> - uses Perl attributes to declare candidates to
be dispatched to. Pluggable dispatching, but by default uses argument
count.
L<Sub::Multi> - syntax wrapper around Class::Multimethods::Pure?
L<Sub::SmartMatch> - kind of abandoned and smartmatch is generally seen
as teh evilz these days.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 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.
=head1 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 2.006 seconds using v1.01-cache-2.11-cpan-e1769b4cff6 )