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 :  /proc/thread-self/root/proc/self/root/usr/share/doc/perl-Moose/t/exceptions/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/proc/self/root/usr/share/doc/perl-Moose/t/exceptions/overload.t
use strict;
use warnings;

use Test::More 0.96;
use Moose::Exception;

subtest 'regular string messages' => sub
{
    my $exception = Moose::Exception->new(message => 'barf!');

    like($exception, qr/barf/, 'stringification for regex works');

    ok($exception ne 'oh hai', 'direct string comparison works');

    ok($exception, 'exception can be treated as a boolean');
};

{
    package MyException;
    sub new {
        my ($class, $message) = @_;
        bless \$message;
    }
    use overload(
        q{""}    => sub { ${$_[0]} },
        fallback => 1,
    );
}

subtest 'message objects' => sub
{
    my $message = MyException->new('barf!');
    is(ref($message), 'MyException', 'exception message is an object');
    is($message, 'barf!', '...which stringifies to the message string');

    my $exception = Moose::Exception->new(message => $message);

    like($exception, qr/barf/, 'stringification for regex works');

    ok($exception ne 'oh hai', 'direct string comparison works');

    ok($exception, 'exception can be treated as a boolean');
};

done_testing;

Hry