Exception-Base

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

* Read-only attributes can be defined with pragma interface.

Removed:

* Removed methods: try, with.

* Removed export of try/catch/throw methods and :all tag.

Changes:

* Reference arguments stored as caller_stack are weakened if it is possible.

* catch method takes no arguments.

0.1901  2008-10-13      Piotr Roszatycki <dexter@debian.org>

Fixes:

* Some warnings disabled.

* Added missing test file to manifest.

README.md  view on Meta::CPAN

- caller\_stack (ro)

    Contains the error stack as array of array with information about caller
    functions.  The first 8 elements of the array's row are the same as first 8
    elements of the output of `caller` function.  Further elements are optional
    and are the arguments of called function.  Collected if the verbosity on
    throwing exception was greater than 1.  Contains only the first element of
    caller stack if the verbosity was lower than 3.

    If the arguments of called function are references and
    `[Scalar::Util](https://metacpan.org/pod/Scalar::Util)::weaken` function is available then reference is weakened.

        eval { Exception::Base->throw( message=>"Message" ); };
        ($package, $filename, $line, $subroutine, $hasargs, $wantarray,
        $evaltext, $is_require, @args) = $@->caller_stack->[0];

- propagated\_stack (ro)

    Contains the array of array which is used for generating "...propagated at"
    message.  The elements of the array's row are the same as first 3 elements of
    the output of `caller` function.

lib/Exception/Base.pm  view on Meta::CPAN

    };
    if (not $@) {
        *_qualify_to_ref = \*Symbol::qualify_to_ref;
    }
    else {
        *_qualify_to_ref = sub ($;) { no strict 'refs'; \*{ $_[0] } };
    };
};


# Use weaken ref on stack if available
BEGIN {
    eval {
        require Scalar::Util;
        my $ref = \1;
        Scalar::Util::weaken($ref);
    };
    if (not $@) {
        *_HAVE_SCALAR_UTIL_WEAKEN = sub () { !! 1 };
    }
    else {
        *_HAVE_SCALAR_UTIL_WEAKEN = sub () { !! 0 };
    };
};


lib/Exception/Base.pm  view on Meta::CPAN

=item caller_stack (ro)

Contains the error stack as array of array with information about caller
functions.  The first 8 elements of the array's row are the same as first 8
elements of the output of C<caller> function.  Further elements are optional
and are the arguments of called function.  Collected if the verbosity on
throwing exception was greater than 1.  Contains only the first element of
caller stack if the verbosity was lower than 3.

If the arguments of called function are references and
C<L<Scalar::Util>::weaken> function is available then reference is weakened.

  eval { Exception::Base->throw( message=>"Message" ); };
  ($package, $filename, $line, $subroutine, $hasargs, $wantarray,
  $evaltext, $is_require, @args) = $@->caller_stack->[0];

=cut

    $ATTRS{caller_stack}         = { is => 'ro' };

=item propagated_stack (ro)

lib/Exception/Base.pm  view on Meta::CPAN

        my @caller_stack;
        my $level = 1;

        while (my @c = do { package DB; caller($level++) }) {
            # Skip own package
            next if ! defined $Isa_Package{$c[0]} ? $Isa_Package{$c[0]} = do { local $@; local $SIG{__DIE__}; eval { $c[0]->isa(__PACKAGE__) } } : $Isa_Package{$c[0]};
            # Collect the caller stack
            my @args = @DB::args;
            if (_HAVE_SCALAR_UTIL_WEAKEN) {
                foreach (@args) {
                    Scalar::Util::weaken($_) if ref $_;
                };
            };
            my @stacktrace_element = ( @c[0 .. 7], @args );
            push @caller_stack, \@stacktrace_element;
            # Collect only one entry if verbosity is lower than 3 and skip ignored packages
            last if $verbosity == 2 and not $self->_skip_ignored_package($stacktrace_element[0]);
        };
        $self->{caller_stack} = \@caller_stack;
    };



( run in 0.552 second using v1.01-cache-2.11-cpan-65fba6d93b7 )