Carton
view release on metacpan or search on metacpan
lib/Carton/Snapshot.pm view on Meta::CPAN
package Carton::Snapshot;
use strict;
use Config;
use Carton::Dist;
use Carton::Dist::Core;
use Carton::Error;
use Carton::Package;
use Carton::Index;
use Carton::Util;
use Carton::Snapshot::Emitter;
use Carton::Snapshot::Parser;
use CPAN::Meta;
use CPAN::Meta::Requirements;
use File::Find ();
use Try::Tiny;
use Path::Tiny ();
use Module::CoreList;
use constant CARTON_SNAPSHOT_VERSION => '1.0';
use subs 'path';
use Class::Tiny {
path => undef,
version => sub { CARTON_SNAPSHOT_VERSION },
loaded => undef,
_distributions => sub { +[] },
};
sub BUILD {
my $self = shift;
$self->path( $self->{path} );
}
sub path {
my $self = shift;
if (@_) {
$self->{path} = Path::Tiny->new($_[0]);
} else {
$self->{path};
}
}
sub load_if_exists {
my $self = shift;
$self->load if $self->path->is_file;
}
sub load {
my $self = shift;
return 1 if $self->loaded;
if ($self->path->is_file) {
my $parser = Carton::Snapshot::Parser->new;
$parser->parse($self->path->slurp_utf8, $self);
$self->loaded(1);
return 1;
} else {
Carton::Error::SnapshotNotFound->throw(
error => "Can't find cpanfile.snapshot: Run `carton install` to build the snapshot file.",
path => $self->path,
);
}
}
sub save {
my $self = shift;
$self->path->spew_utf8( Carton::Snapshot::Emitter->new->emit($self) );
}
sub find {
my($self, $module) = @_;
(grep $_->provides_module($module), $self->distributions)[0];
}
( run in 1.012 second using v1.01-cache-2.11-cpan-5fbc6bb55f2 )