Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$@ is unstable in all perl versions #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,27 @@ The destructor is called when the stack is unwound, after C<die> sets C<$@> to
C<"foo at Foo.pm line 42\n">, so by the time C<if ( $@ )> is evaluated it has
been cleared by C<eval> in the destructor.

=head2 $@ might be a true value when eval succeeded

Similar as in above example. It is possible to manually set C<$@> value and if
it happens when the stack is unwound it propagate false information back to
caller.

sub Object::DESTROY {
$@ = "some string";
}

eval {
my $obj = Object->new;
};

if ( $@ ) {

}

In this case after C<eval> the value in C<$@> is set to C<"some string"> and
evaluated to true. Even C<eval> itself succeeded.

The workaround for this is even uglier than the previous ones. Even though we
can't save the value of C<$@> from code that doesn't localize, we can at least
be sure the C<eval> was aborted due to an error:
Expand Down
21 changes: 21 additions & 0 deletions lib/Try/Tiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,27 @@ The destructor is called when the stack is unwound, after C<die> sets C<$@> to
C<"foo at Foo.pm line 42\n">, so by the time C<if ( $@ )> is evaluated it has
been cleared by C<eval> in the destructor.

=head2 $@ might be a true value when eval succeeded

Similar as in above example. It is possible to manually set C<$@> value and if
it happens when the stack is unwound it propagate false information back to
caller.

sub Object::DESTROY {
$@ = "some string";
}

eval {
my $obj = Object->new;
};

if ( $@ ) {

}

In this case after C<eval> the value in C<$@> is set to C<"some string"> and
evaluated to true. Even C<eval> itself succeeded.

The workaround for this is even uglier than the previous ones. Even though we
pali marked this conversation as resolved.
Show resolved Hide resolved
can't save the value of C<$@> from code that doesn't localize, we can at least
be sure the C<eval> was aborted due to an error:
Expand Down