It will close when Perl hits the semi-colon, because that is when Perl realises the object has gone out of scope.
Quick demo:
use v5.14;
package Foo {
sub new {
my $class = shift;
say "new";
bless [] => $class;
}
sub some_method {
my $self = shift;
say "some_method";
return $self;
}
sub other_method {
my $self = shift;
say "other_method";
return 123;
}
sub DESTROY {
my $self = shift;
say "DESTROY";
}
}
say "START";
say Foo->new->some_method->other_method and say 456;
say "END";
DESTROY happens after "456" is printed, but before "END".
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
|