| 1 | # Copyright 2011-2026, Paul Johnson (paul@pjcj.net) | ||
| 2 | |||
| 3 | # This software is free. It is licensed under the same terms as Perl itself. | ||
| 4 | |||
| 5 | # The latest version of this software should be available from my homepage: | ||
| 6 | # https://pjcj.net | ||
| 7 | |||
| 8 | package Devel::Cover::DB::IO; | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | |||
| 13 | our $VERSION = '1.52'; # VERSION | ||
| 14 | |||
| 15 | my $Format; | ||
| 16 | |||
| 17 | BEGIN { | ||
| 18 | $Format = "Sereal" if eval "use Sereal::Decoder; use Sereal::Encoder; 1"; | ||
| 19 | $Format = "JSON" if !$Format and eval { require JSON::MaybeXS; 1 }; | ||
| 20 | $Format = "Storable" if !$Format and eval "use Storable; 1"; | ||
| 21 | die "Can't load either JSON or Storable" unless $Format; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub new { | ||
| 25 | my $class = shift; | ||
| 26 | |||
| 27 | my $format = $ENV{DEVEL_COVER_DB_FORMAT} || $Format; | ||
| 28 | ($format) = $format =~ /(.*)/; # die tainting | ||
| 29 | die "Devel::Cover: Unrecognised DB format: $format" | ||
| 30 | unless $format =~ /^(?:Storable|JSON|Sereal)$/; | ||
| 31 | |||
| 32 | $class .= "::$format"; | ||
| 33 | eval "use $class; 1" or die "Devel::Cover: $@"; | ||
| 34 | |||
| 35 | $class->new(options => $ENV{DEVEL_COVER_IO_OPTIONS} || "", @_) | ||
| 36 | } | ||
| 37 | |||
| 38 | 1 | ||
| 39 | |||
| 40 | __END__ |