Test::MinimumVersion.max_target_perl = 5.008000
; these appear in every file, so it's easier to just put it here
Test::PodSpelling.stopwords = cpan
-; these are all the modules that use optional prereqs, and will cause
-; cpantesters to barf in the compile tests
-Test::Compile.skip[] = ^MooseX::Storage::((Engine::)?IO::|Format::)
[Prereqs / RuntimeRequires]
Moose = 0.99
package MooseX::Storage::Engine::IO::AtomicFile;
use Moose;
-use IO::AtomicFile;
-
extends 'MooseX::Storage::Engine::IO::File';
sub store {
my ($self, $data) = @_;
+ require IO::AtomicFile;
my $fh = IO::AtomicFile->new($self->file, 'w')
|| confess "Unable to open file (" . $self->file . ") for storing : $!";
$fh->binmode(':utf8') if utf8::is_utf8($data);
package MooseX::Storage::Engine::IO::File;
use Moose;
-use IO::File;
-
has 'file' => (
is => 'ro',
isa => 'Str',
sub load {
my ($self) = @_;
+
+ require IO::File;
my $fh = IO::File->new($self->file, 'r')
|| confess "Unable to open file (" . $self->file . ") for loading : $!";
return do { local $/; <$fh>; };
sub store {
my ($self, $data) = @_;
+
+ require IO::File;
my $fh = IO::File->new($self->file, 'w')
|| confess "Unable to open file (" . $self->file . ") for storing : $!";
$fh->binmode(':utf8') if utf8::is_utf8($data);
no warnings 'once';
-use JSON::Any;
-
requires 'pack';
requires 'unpack';
sub thaw {
my ( $class, $json, @args ) = @_;
+
+ require JSON::Any;
+
utf8::encode($json) if utf8::is_utf8($json);
$class->unpack( JSON::Any->new->jsonToObj($json), @args );
}
sub freeze {
my ( $self, @args ) = @_;
+
+ require JSON::Any;
+
my $json = JSON::Any->new(canonical => 1)->objToJson( $self->pack(@args) );
utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json); # if it's valid utf8 mark it as such
return $json;
package MooseX::Storage::Format::Storable;
use Moose::Role;
-use Storable ();
-
requires 'pack';
requires 'unpack';
sub thaw {
my ( $class, $stored, @args ) = @_;
+
+ require Storable;
$class->unpack( Storable::thaw($stored), @args );
}
sub freeze {
my ( $self, @args ) = @_;
+ require Storable;
Storable::nfreeze( $self->pack(@args) );
}
# Tests break because tye YAML is invalid...?
# -dcp
-use YAML::Any qw(Load Dump);
-
requires 'pack';
requires 'unpack';
sub thaw {
my ( $class, $yaml, @args ) = @_;
- $class->unpack( Load($yaml), @args );
+ require YAML::Any;
+ $class->unpack( YAML::Any::Load($yaml), @args );
}
sub freeze {
my ( $self, @args ) = @_;
+ require YAML::Any;
Dump( $self->pack(@args) );
}
package MooseX::Storage::IO::StorableFile;
use Moose::Role;
-use Storable ();
-
requires 'pack';
requires 'unpack';
sub load {
my ( $class, $filename, @args ) = @_;
+
+ require Storable;
+
# try thawing
return $class->thaw( Storable::retrieve($filename), @args )
if $class->can('thaw');
sub store {
my ( $self, $filename, @args ) = @_;
+
+ require Storable;
+
Storable::nstore(
# try freezing, otherwise just pack
($self->can('freeze') ? $self->freeze(@args) : $self->pack(@args)),