Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/Path/Tiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,23 @@ sub is_rootdir {
return $self->[DIR] eq '/' && $self->[FILE] eq '';
}

=method is_temporary

my $temp = Path::Tiny->tempfile;
if ($temp->is_temporary) {
...
}

Returns true if the C<Path::Tiny> object was created by C<tempfile> or
C<tempdir>. Returns false otherwise.

=cut

sub is_temporary {
my ($self) = @_;
!!eval { $self->cached_temp; 1 };
}

=method iterator

$iter = path("/tmp")->iterator( \%options );
Expand Down
9 changes: 9 additions & 0 deletions t/temp.t
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,14 @@ subtest "tempfile, instance method, overridden DIR" => sub {
ok( $tempfile->parent ne $bd ), "DIR is overridden";
};

subtest "is_temporary" => sub {
my $tempdir = Path::Tiny->tempdir;
ok( $tempdir->is_temporary, "tempdir is temporary" );
my $tempfile = Path::Tiny->tempfile;
ok( $tempfile->is_temporary, "tempfile is temporary" );
my $path = path("abcdefg");
ok( !$path->is_temporary, "regular path is not temporary" );
};

done_testing;
# COPYRIGHT