NAME

Contextual::Diag::Value - wrapping scalar value for diagnostics

SYNOPSIS

    use Contextual::Diag::Value;

    my $value = 'hello';
    my $v = Contextual::Diag::Value->new($value,
        BOOL => sub { warn 'evaluated as BOOL';  return $_[0] },
    );

    if ($v) { }
    # => warn 'evaluated as BOOL';

new($value, %overload)

Constructor for Contextual::Diag::Value:

    Contextual::Diag::Value->new($_[0],
        BOOL      => sub { $_[0] },
        NUM       => sub { $_[0] || 0   },
        STR       => sub { $_[0] || ""  },
        SCALARREF => sub { defined $_[0] ? $_[0] : \"" },
        ARRAYREF  => sub { defined $_[0] ? $_[0] : [] },
        HASHREF   => sub { defined $_[0] ? $_[0] : {} },
        CODEREF   => sub { defined $_[0] ? $_[0] : sub { } },
        GLOBREF   => sub { defined $_[0] ? $_[0] : do { no strict qw/refs/; my $package = __PACKAGE__; \*{$package} } },
        OBJREF    => sub { defined $_[0] ? $_[0] : bless {}, __PACKAGE__ },
    );

OTHER METHODS

can

Override can to hook OBJREF.

isa

Override isa to hook OBJREF.

SEE ALSO

Contextual::Return

LICENSE

Copyright (C) kfly8.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

kfly8 <kfly@cpan.org>