Skip to content

Commit

Permalink
Replaced JSON::Any with JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
semifor committed Sep 22, 2011
1 parent cbcb834 commit 8ccf3fd
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 32 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,3 +1,4 @@
- Replaced JSON::Any with JSON
- documented new arguments for friendship_exists - documented new arguments for friendship_exists


3.18000_01 2011-09-21 3.18000_01 2011-09-21
Expand Down
20 changes: 1 addition & 19 deletions Makefile.PL
Expand Up @@ -31,7 +31,7 @@ requires 'Digest::HMAC_SHA1';
requires 'Encode'; requires 'Encode';
requires 'HTML::Entities'; requires 'HTML::Entities';
requires 'HTTP::Request::Common'; requires 'HTTP::Request::Common';
requires 'JSON::Any' => 1.21; requires 'JSON';
requires 'LWP::UserAgent' => 2.032; requires 'LWP::UserAgent' => 2.032;
requires 'Moose' => 0.90; requires 'Moose' => 0.90;
requires 'Moose::Exporter'; requires 'Moose::Exporter';
Expand All @@ -49,24 +49,6 @@ requires 'Try::Tiny' => 0.03;
test_requires 'Test::Fatal'; test_requires 'Test::Fatal';
test_requires 'Test::More' => 0.88; # for done_testing 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 => 'src';
no_index directory => 'examples'; no_index directory => 'examples';


Expand Down
3 changes: 2 additions & 1 deletion lib/Net/Twitter.pm
@@ -1,6 +1,7 @@
package Net::Twitter; package Net::Twitter;
use Moose; use Moose;
use Carp; use Carp;
use JSON;
use Net::Twitter::Core; use Net::Twitter::Core;
use Digest::SHA qw/sha1_hex/; use Digest::SHA qw/sha1_hex/;


Expand Down Expand Up @@ -88,7 +89,7 @@ sub _create_anon_class {
my $t = shift @t; my $t = shift @t;
if ( ref $t[0] eq 'HASH' ) { if ( ref $t[0] eq 'HASH' ) {
my $params = shift @t; 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; my $sn = $serial_for_params{$sig} ||= ++$serial_number;
$t .= "_$sn"; $t .= "_$sn";
} }
Expand Down
6 changes: 3 additions & 3 deletions lib/Net/Twitter/Core.pm
Expand Up @@ -3,7 +3,7 @@ use 5.008001;
use Moose; use Moose;
use MooseX::Aliases; use MooseX::Aliases;
use Carp; use Carp;
use JSON::Any qw/XS JSON/; use JSON;
use URI::Escape; use URI::Escape;
use HTTP::Request::Common; use HTTP::Request::Common;
use Net::Twitter::Error; use Net::Twitter::Error;
Expand Down Expand Up @@ -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 _base_url => ( is => 'rw' ); ### keeps role composition from bitching ??
has _json_handler => ( has _json_handler => (
is => 'rw', is => 'rw',
default => sub { JSON::Any->new(utf8 => 1) }, default => sub { JSON->new->utf8 },
handles => { _from_json => 'from_json' }, handles => { _from_json => 'decode' },
); );


sub _synthetic_args { qw/authenticate since/ } sub _synthetic_args { qw/authenticate since/ }
Expand Down
3 changes: 2 additions & 1 deletion t/20_exceptions.t
Expand Up @@ -3,6 +3,7 @@ use warnings;
use strict; use strict;
use Test::More; use Test::More;
use Test::Fatal; use Test::Fatal;
use JSON qw/to_json/;
use lib qw(t/lib); use lib qw(t/lib);
use Net::Twitter; use Net::Twitter;


Expand All @@ -18,7 +19,7 @@ my $nt = Net::Twitter->new(
my $t = TestUA->new($nt->ua); my $t = TestUA->new($nt->ua);


my $response = HTTP::Response->new(404, 'Not Found'); my $response = HTTP::Response->new(404, 'Not Found');
$response->content(JSON::Any->to_json({ $response->content(to_json({
request => '/direct_messages/destroy/456.json', request => '/direct_messages/destroy/456.json',
error => 'No direct message with that ID found.', error => 'No direct message with that ID found.',
})); }));
Expand Down
5 changes: 3 additions & 2 deletions t/50_inflate_objects.t
Expand Up @@ -3,6 +3,7 @@ use warnings;
use strict; use strict;
use Scalar::Util qw/blessed/; use Scalar::Util qw/blessed/;
use Test::More; use Test::More;
use JSON qw/to_json/;
use lib qw(t/lib); use lib qw(t/lib);


eval 'use TestUA'; eval 'use TestUA';
Expand All @@ -23,7 +24,7 @@ my $dt = DateTime->now;
$dt->subtract(minutes => 6); $dt->subtract(minutes => 6);


my $t = TestUA->new($nt->ua); my $t = TestUA->new($nt->ua);
$t->response->content(JSON::Any->to_json([{ $t->response->content(to_json([{
text => 'Hello, twittersphere!', text => 'Hello, twittersphere!',
user => { user => {
screen_name => 'net_twitter', screen_name => 'net_twitter',
Expand All @@ -42,7 +43,7 @@ is $object->relative_created_at, '6 minutes ago', 'relative_created_at';
is $object->user->screen_name, 'net_twitter', 'nested objects'; is $object->user->screen_name, 'net_twitter', 'nested objects';


# make sure we don't co-mingle our object methods # make sure we don't co-mingle our object methods
$t->response->content(JSON::Any->to_json({ $t->response->content(to_json({
foo => 'foo', foo => 'foo',
bar => 'bar', bar => 'bar',
baz => 'and of course, baz', baz => 'and of course, baz',
Expand Down
5 changes: 3 additions & 2 deletions t/51_rate_limit.t
Expand Up @@ -2,6 +2,7 @@
use warnings; use warnings;
use strict; use strict;
use Test::More; use Test::More;
use JSON qw/to_json/;
use lib qw(t/lib); use lib qw(t/lib);
use Net::Twitter; use Net::Twitter;


Expand All @@ -12,7 +13,7 @@ my $nt = Net::Twitter->new(traits => [qw/API::REST RateLimit/]);


my $reset = time + 1800; my $reset = time + 1800;
my $t = TestUA->new($nt->ua); my $t = TestUA->new($nt->ua);
$t->response->content(JSON::Any->to_json({ $t->response->content(to_json({
remaining_hits => 75, remaining_hits => 75,
reset_time_in_seconds => $reset, reset_time_in_seconds => $reset,
hourly_limit => 150, hourly_limit => 150,
Expand All @@ -32,7 +33,7 @@ ok $until > 890 && $until < 910, 'until_rate(2.0) is about 900';




# test clock mismatch # test clock mismatch
$t->response->content(JSON::Any->to_json({ $t->response->content(to_json({
remaining_hits => 10, remaining_hits => 10,
reset_time_in_seconds => $nt->_rate_limit_status->{rate_reset} = time - 10, reset_time_in_seconds => $nt->_rate_limit_status->{rate_reset} = time - 10,
hourly_limit => 150, hourly_limit => 150,
Expand Down
3 changes: 2 additions & 1 deletion t/51_since.t
Expand Up @@ -4,6 +4,7 @@ use strict;
use Try::Tiny; use Try::Tiny;
use Scalar::Util qw/blessed/; use Scalar::Util qw/blessed/;
use Test::More; use Test::More;
use JSON qw/to_json/;
use lib qw(t/lib); use lib qw(t/lib);


eval 'use TestUA'; eval 'use TestUA';
Expand All @@ -24,7 +25,7 @@ my $dt = DateTime->now;
$dt->subtract(minutes => 6); $dt->subtract(minutes => 6);


my $t = TestUA->new($nt->ua); my $t = TestUA->new($nt->ua);
$t->response->content(JSON::Any->to_json([ $t->response->content(to_json([
{ {
text => 'Hello, twittersphere!', text => 'Hello, twittersphere!',
id => 1234, id => 1234,
Expand Down
6 changes: 3 additions & 3 deletions t/auto-cursor.t
Expand Up @@ -3,10 +3,10 @@ use warnings;
use strict; use strict;
use Test::More; use Test::More;
use Net::Twitter; use Net::Twitter;
use JSON::Any; use JSON qw/to_json/;
use HTTP::Response; 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 { sub mock_ua {
my $nt = shift; my $nt = shift;


Expand All @@ -25,7 +25,7 @@ sub mock_ua {
my $nt_with_max_calls_4 = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 4 }]); 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 $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; mock_ua($_) for $nt_with_max_calls_2, $nt_with_max_calls_4;


Expand Down

0 comments on commit 8ccf3fd

Please sign in to comment.