Skip to content

Commit

Permalink
JSON is not required, JSON::PP will do.
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcj committed Apr 14, 2012
1 parent c64171a commit cd862b2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
39 changes: 24 additions & 15 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -138,42 +138,52 @@ push @tests, grep !/e2e/, glob "t/*/*.t";

print "done\n\n";

my %checked;

sub check
{
my ($module, $text, $version) = @_;

printf "checking for %-18s %-16s .... ",
$module, $version ? "version $version" : "";

eval "use $module";
{
local $SIG{__WARN__} = sub {};
eval "use $module";
}
(my $mod = $module) =~ s/::/\//g;
if (my $m = $INC{"$mod.pm"})
{
my $v = eval { no warnings; eval "\$${module}::VERSION" };
printf "%-8s $m\n", $v;
if ($version && $v < $version)
{
print "\n\n\n$text\n\n";
print "\n\n\n$text\n" unless $checked{$text}++;
print "\n";
}
}
else
{
print "not found\n\n\n$text\n\n";
print "not found";
print "\n\n\n$text\n" unless $checked{$text}++;
print "\n";
}
};

check "Storable", <<EOM;
Storable is required to store the coverage database. You can download
Storable from CPAN.
my $d = <<EOM;
The coverage database can be stored in either Storable format or in JSON. To
use the Storable format, the Storable module is required. This has been a
core module since perl-5.8.0. To store the database in JSON format JSON::PP
can be used. This has been a core module since perl-5.14.0. If you wish, you
may install the JSON module which will be used in preference. This may be
configured to make database operations faster. If both formats are available,
JSON will be preferred by default. The JSON format should be portable between
all systems, whereas Storable format may not be.
EOM

check "JSON", <<EOM;
JSON is required to store the coverage database in a portable format.
This is necessary in order to merge coverage data from incompatible systems.
Storing the database in a portable format will not be available until you
install JSON. In the meantime you may continue to use the rest of
Devel::Cover.
EOM
check "Storable", $d;
check "JSON", $d;
check "JSON::PP", $d;

check "Digest::MD5", <<EOM;
Digest::MD5 is required to check whether covered files have changed. You can
Expand Down Expand Up @@ -207,8 +217,7 @@ PPI::HTML or Perl::Tidy, available from the CPAN. In the meantime you
may continue to use the rest of Devel::Cover.
EOM

check "PPI::HTML", $m, "1.07";

check "PPI::HTML", $m, "1.07";
check "Perl::Tidy", $m, "20060719";

print "checking for Pod::Coverage version 0.06 .... ";
Expand Down
1 change: 0 additions & 1 deletion dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Pod::Coverage = 0.06
Pod::Coverage::CountParents = 0
Parallel::Iterator = 0
JSON::PP = 0
JSON::XS = 0
Test::Differences = 0 ; make sure it gets added
[Prereqs / ConfigureRequires]
ExtUtils::MakeMaker = 0
Expand Down
5 changes: 2 additions & 3 deletions lib/Devel/Cover/DB/IO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ my $Format;

BEGIN
{
$Format = "JSON" if eval "use JSON; 1";
# warn "JSON available\n" if $INC{"JSON.pm"};
$Format = "JSON" if eval "use JSON; 1";
$Format = "JSON" if !$Format and eval "use JSON:PP; 1";
$Format = "Storable" if !$Format and eval "use Storable; 1";
# warn "Storable available\n" if $INC{"Storable.pm"};
die "Can't load either JSON or Storable" unless $Format;
}

Expand Down
17 changes: 14 additions & 3 deletions lib/Devel/Cover/DB/IO/JSON.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ use strict;
use warnings;

use Fcntl ":flock";
use JSON;

# VERSION

my $Format;

BEGIN
{
$Format = "JSON" if eval "use JSON; 1";
$Format = "JSON::PP" if !$Format and eval "use JSON::PP; 1";
die "Can't load either JSON or JSON::PP" unless $Format;
}

sub new
{
my $class = shift;
Expand All @@ -30,7 +38,9 @@ sub read
open my $fh, "<", $file or die "Can't open $file: $!";
flock($fh, LOCK_SH) or die "Cannot lock file: $!\n";
local $/;
my $data = JSON::decode_json(<$fh>);
my $data = $Format eq "JSON"
? JSON::decode_json(<$fh>)
: JSON::PP::decode_json(<$fh>);
close $fh or die "Can't close $file: $!";
$data
}
Expand All @@ -40,7 +50,8 @@ sub write
my $self = shift;
my ($data, $file) = @_;

my $json = JSON->new->utf8->allow_blessed;
my $json = $Format eq "JSON" ? JSON->new : JSON::PP->new;
$json->utf8->allow_blessed;
$json->ascii->pretty->canonical if $self->{options} =~ /\bpretty\b/i;
open my $fh, ">", $file or die "Can't open $file: $!";
flock($fh, LOCK_EX) or die "Cannot lock file: $!\n";
Expand Down

0 comments on commit cd862b2

Please sign in to comment.