Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /usr/share/doc/perl-Moose/t/cmop/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/perl-Moose/t/cmop/random_eval_bug.t
use strict;
use warnings;

use Test::More;

use Class::MOP;

=pod

This tests a bug which is fixed in 0.22 by localizing all the $@'s around any
evals.

This a real pain to track down.

Moral of the story:

  ALWAYS localize your globals :)

=cut

{
    package Company;
    use strict;
    use warnings;
    use metaclass;

    sub new {
        my ($class) = @_;
        return bless {} => $class;
    }

    sub employees {
        die "This didnt work";
    }

    sub DESTROY {
        my $self = shift;
        foreach
            my $method ( $self->meta->find_all_methods_by_name('DEMOLISH') ) {
            $method->{code}->($self);
        }
    }
}

eval {
    my $c = Company->new();
    $c->employees();
};
ok( $@, '... we die correctly with bad args' );

done_testing;

Hry