summaryrefslogtreecommitdiff
path: root/lib/Carton/Lockfile.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Carton/Lockfile.pm')
-rw-r--r--lib/Carton/Lockfile.pm30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/Carton/Lockfile.pm b/lib/Carton/Lockfile.pm
new file mode 100644
index 0000000..f4ea3be
--- /dev/null
+++ b/lib/Carton/Lockfile.pm
@@ -0,0 +1,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;
+