Permalink
Browse files

Replaced JSON::Any with JSON

  • Loading branch information...
1 parent cbcb834 commit 8ccf3fd5dea33a277ba268dc1ff37ef847caf730 @semifor committed Sep 22, 2011
Showing with 20 additions and 32 deletions.
  1. +1 −0 Changes
  2. +1 −19 Makefile.PL
  3. +2 −1 lib/Net/Twitter.pm
  4. +3 −3 lib/Net/Twitter/Core.pm
  5. +2 −1 t/20_exceptions.t
  6. +3 −2 t/50_inflate_objects.t
  7. +3 −2 t/51_rate_limit.t
  8. +2 −1 t/51_since.t
  9. +3 −3 t/auto-cursor.t
View
@@ -1,3 +1,4 @@
+ - Replaced JSON::Any with JSON
- documented new arguments for friendship_exists
3.18000_01 2011-09-21
View
@@ -31,7 +31,7 @@ requires 'Digest::HMAC_SHA1';
requires 'Encode';
requires 'HTML::Entities';
requires 'HTTP::Request::Common';
-requires 'JSON::Any' => 1.21;
+requires 'JSON';
requires 'LWP::UserAgent' => 2.032;
requires 'Moose' => 0.90;
requires 'Moose::Exporter';
@@ -49,24 +49,6 @@ requires 'Try::Tiny' => 0.03;
test_requires 'Test::Fatal';
test_requires 'Test::More' => 0.88; # for done_testing
-# Don't rely on the JSON::Any requirement to pull in a suitable JSON backend.
-# The user may already have JSON::Any installed, but since removed all valid
-# providers. (Yes, this seems to have happened in the wild.)
-sub has_json_xs () {
- my @order = qw/JSON::XS/;
- for my $provider ( @order ) {
- eval "require $provider";
- return 1 unless $@;
- }
- return;
-}
-
-if (has_json_xs()) {
- requires 'JSON::XS' => 0;
-} else {
- requires 'JSON' => '2.02';
-}
-
no_index directory => 'src';
no_index directory => 'examples';
View
@@ -1,6 +1,7 @@
package Net::Twitter;
use Moose;
use Carp;
+use JSON;
use Net::Twitter::Core;
use Digest::SHA qw/sha1_hex/;
@@ -88,7 +89,7 @@ sub _create_anon_class {
my $t = shift @t;
if ( ref $t[0] eq 'HASH' ) {
my $params = shift @t;
- my $sig = sha1_hex(JSON::Any->to_json($params));
+ my $sig = sha1_hex(JSON->new->utf8->encode($params));
my $sn = $serial_for_params{$sig} ||= ++$serial_number;
$t .= "_$sn";
}
@@ -3,7 +3,7 @@ use 5.008001;
use Moose;
use MooseX::Aliases;
use Carp;
-use JSON::Any qw/XS JSON/;
+use JSON;
use URI::Escape;
use HTTP::Request::Common;
use Net::Twitter::Error;
@@ -41,8 +41,8 @@ has clienturl => ( isa => 'Str', is => 'ro', default => 'http://search.cpa
has _base_url => ( is => 'rw' ); ### keeps role composition from bitching ??
has _json_handler => (
is => 'rw',
- default => sub { JSON::Any->new(utf8 => 1) },
- handles => { _from_json => 'from_json' },
+ default => sub { JSON->new->utf8 },
+ handles => { _from_json => 'decode' },
);
sub _synthetic_args { qw/authenticate since/ }
View
@@ -3,6 +3,7 @@ use warnings;
use strict;
use Test::More;
use Test::Fatal;
+use JSON qw/to_json/;
use lib qw(t/lib);
use Net::Twitter;
@@ -18,7 +19,7 @@ my $nt = Net::Twitter->new(
my $t = TestUA->new($nt->ua);
my $response = HTTP::Response->new(404, 'Not Found');
-$response->content(JSON::Any->to_json({
+$response->content(to_json({
request => '/direct_messages/destroy/456.json',
error => 'No direct message with that ID found.',
}));
@@ -3,6 +3,7 @@ use warnings;
use strict;
use Scalar::Util qw/blessed/;
use Test::More;
+use JSON qw/to_json/;
use lib qw(t/lib);
eval 'use TestUA';
@@ -23,7 +24,7 @@ my $dt = DateTime->now;
$dt->subtract(minutes => 6);
my $t = TestUA->new($nt->ua);
-$t->response->content(JSON::Any->to_json([{
+$t->response->content(to_json([{
text => 'Hello, twittersphere!',
user => {
screen_name => 'net_twitter',
@@ -42,7 +43,7 @@ is $object->relative_created_at, '6 minutes ago', 'relative_created_at';
is $object->user->screen_name, 'net_twitter', 'nested objects';
# make sure we don't co-mingle our object methods
-$t->response->content(JSON::Any->to_json({
+$t->response->content(to_json({
foo => 'foo',
bar => 'bar',
baz => 'and of course, baz',
View
@@ -2,6 +2,7 @@
use warnings;
use strict;
use Test::More;
+use JSON qw/to_json/;
use lib qw(t/lib);
use Net::Twitter;
@@ -12,7 +13,7 @@ my $nt = Net::Twitter->new(traits => [qw/API::REST RateLimit/]);
my $reset = time + 1800;
my $t = TestUA->new($nt->ua);
-$t->response->content(JSON::Any->to_json({
+$t->response->content(to_json({
remaining_hits => 75,
reset_time_in_seconds => $reset,
hourly_limit => 150,
@@ -32,7 +33,7 @@ ok $until > 890 && $until < 910, 'until_rate(2.0) is about 900';
# test clock mismatch
-$t->response->content(JSON::Any->to_json({
+$t->response->content(to_json({
remaining_hits => 10,
reset_time_in_seconds => $nt->_rate_limit_status->{rate_reset} = time - 10,
hourly_limit => 150,
View
@@ -4,6 +4,7 @@ use strict;
use Try::Tiny;
use Scalar::Util qw/blessed/;
use Test::More;
+use JSON qw/to_json/;
use lib qw(t/lib);
eval 'use TestUA';
@@ -24,7 +25,7 @@ my $dt = DateTime->now;
$dt->subtract(minutes => 6);
my $t = TestUA->new($nt->ua);
-$t->response->content(JSON::Any->to_json([
+$t->response->content(to_json([
{
text => 'Hello, twittersphere!',
id => 1234,
View
@@ -3,10 +3,10 @@ use warnings;
use strict;
use Test::More;
use Net::Twitter;
-use JSON::Any;
+use JSON qw/to_json/;
use HTTP::Response;
-my $json_result = JSON::Any->to_json({ ids => ['test'], next_cursor => 1 });
+my $json_result = to_json({ ids => ['test'], next_cursor => 1 });
sub mock_ua {
my $nt = shift;
@@ -25,7 +25,7 @@ sub mock_ua {
my $nt_with_max_calls_4 = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 4 }]);
my $class_for_max_calls_4 = ref $nt_with_max_calls_4;
- my $json_result = JSON::Any->to_json({ ids => ['test'], next_cursor => 1 });
+ my $json_result = to_json({ ids => ['test'], next_cursor => 1 });
mock_ua($_) for $nt_with_max_calls_2, $nt_with_max_calls_4;

0 comments on commit 8ccf3fd

Please sign in to comment.