Skip to content

Instantly share code, notes, and snippets.

@TristinDavis
Forked from xantus/JSON.pm
Created November 16, 2012 01:01
Show Gist options
  • Save TristinDavis/4082950 to your computer and use it in GitHub Desktop.
Save TristinDavis/4082950 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