Skip to content

Instantly share code, notes, and snippets.

@xantus
Created August 2, 2010 19:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xantus/505189 to your computer and use it in GitHub Desktop.
Save xantus/505189 to your computer and use it in GitHub Desktop.
MojoX::JSON
package MojoX::JSON;
use Mojo::JSON;
our $SINGLETON;
BEGIN {
# install JSON::XS if you can!
eval 'use JSON();';
eval ( $@ ? 'sub HAS_JSON(){ 0 }' : 'sub HAS_JSON(){ 1 }' );
};
sub singleton {
$SINGLETON ||= shift->new( @_ );
}
sub new {
return HAS_JSON ? 'JSON'->new( @_[ 1 .. $#_ ] ) : Mojo::JSON->new( @_[ 1 .. $#_ ] );
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment