ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Handle.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.178 by root, Tue Aug 11 01:15:17 2009 UTC vs.
Revision 1.179 by root, Wed Aug 12 15:50:44 2009 UTC

878Other languages could read single lines terminated by a newline and pass 878Other languages could read single lines terminated by a newline and pass
879this line into their JSON decoder of choice. 879this line into their JSON decoder of choice.
880 880
881=cut 881=cut
882 882
883sub json_coder() {
884 eval { require JSON::XS; JSON::XS->new->utf8 }
885 || do { require JSON; JSON->new->utf8 }
886}
887
883register_write_type json => sub { 888register_write_type json => sub {
884 my ($self, $ref) = @_; 889 my ($self, $ref) = @_;
885 890
886 require JSON; 891 my $json = $self->{json} ||= json_coder;
887 892
888 $self->{json} ? $self->{json}->encode ($ref) 893 $json->encode ($ref)
889 : JSON::encode_json ($ref)
890}; 894};
891 895
892=item storable => $reference 896=item storable => $reference
893 897
894Freezes the given reference using L<Storable> and writes it to the 898Freezes the given reference using L<Storable> and writes it to the
1448=cut 1452=cut
1449 1453
1450register_read_type json => sub { 1454register_read_type json => sub {
1451 my ($self, $cb) = @_; 1455 my ($self, $cb) = @_;
1452 1456
1453 my $json = $self->{json} ||= 1457 my $json = $self->{json} ||= json_coder;
1454 eval { require JSON::XS; JSON::XS->new->utf8 }
1455 || do { require JSON; JSON->new->utf8 };
1456 1458
1457 my $data; 1459 my $data;
1458 my $rbuf = \$self->{rbuf}; 1460 my $rbuf = \$self->{rbuf};
1459 1461
1460 sub { 1462 sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines