Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Inherit from Test::Builder::Module.

  • Loading branch information...
commit 0534e51c4b1cc148d0b4957fba6b785fb9ce7246 1 parent f37a741
@Ovid authored
Showing with 8 additions and 19 deletions.
  1. +3 −1 Changes
  2. +5 −18 lib/Test/JSON.pm
View
4 Changes
@@ -1,7 +1,9 @@
Revision history for Test-JSON
0.10 2009-07-03
- Need dependency on JSON::Any 1.20 or greater.
+ Need dependency on JSON::Any 1.20 or greater. This resolves rt #32957
+ Inherit from Test::Builder::Module instead of rolling my own exporter.
+
0.07 2009-06-29
Ensure that we can run with subtests by not having Test::Builder->new
View
23 lib/Test/JSON.pm
@@ -2,10 +2,12 @@ package Test::JSON;
use strict;
use Carp;
-use Test::Builder;
use Test::Differences;
use JSON::Any;
+use base 'Test::Builder::Module';
+our @EXPORT = qw/is_json is_valid_json/;
+
=head1 NAME
Test::JSON - Test JSON data
@@ -20,21 +22,6 @@ our $VERSION = '0.1';
my $JSON = JSON::Any->new;
-sub import {
- my $self = shift;
- my $caller = caller;
-
- my @subs = qw/is_json is_valid_json/;
- foreach my $sub (@subs) {
- no strict 'refs';
- *{"${caller}::$sub"} = \&{$sub};
- }
-
- my $test = Test::Builder->new;
- $test->exported_to($caller);
- $test->plan(@_);
-}
-
=head1 SYNOPSIS
use Test::JSON;
@@ -100,7 +87,7 @@ sub is_valid_json ($;$) {
croak "usage: is_valid_json(input,test_name)"
unless defined $input;
eval { $JSON->decode($input) };
- my $test = Test::Builder->new;
+ my $test = __PACKAGE__->builder;
if ( my $error = $@ ) {
$test->ok( 0, $test_name );
$test->diag("Input was not valid JSON:\n\n\t$error");
@@ -120,7 +107,7 @@ sub is_json ($$;$) {
my %json_for;
foreach my $item ( [ input => $input ], [ expected => $expected ] ) {
my $json = eval { $JSON->decode( $item->[1] ) };
- my $test = Test::Builder->new;
+ my $test = __PACKAGE__->builder;
if ( my $error = $@ ) {
$test->ok( 0, $test_name );
$test->diag("$item->[0] was not valid JSON: $error");
Please sign in to comment.
Something went wrong with that request. Please try again.