summaryrefslogtreecommitdiff
path: root/lib/Carton/Lockfile.pm
blob: f4ea3bef1a4a953ccc61c82a9264a41726e3542e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package Carton::Lockfile;
use strict;
use parent 'Path::Tiny';

sub new {
    my $class = shift;
    my $self = Path::Tiny->new(@_);
    bless $self, $class; # XXX: Path::Tiny doesn't allow subclasses. Should be via Role + handles?
}

sub load_if_exists {
    my $self = shift;
    Carton::Lock->from_file($self) if $self->exists;
}

sub load {
    my $self = shift;

    if ($self->exists) {
        Carton::Lock->from_file($self);
    } else {
        Carton::Error::LockfileNotFound->throw(
            error => "Can't find carton.lock: Run `carton install` to build the lock file.",
            path => $self->stringify,
        );
    }
}

1;