From e75bb05c45954842ac1cb25a8056b3572dea835b Mon Sep 17 00:00:00 2001 From: Graham Ollis Date: Tue, 11 Oct 2022 10:17:35 -0600 Subject: [PATCH] add frame option --- Changes | 2 ++ README.md | 9 ++++++++- lib/Exception/FFI/ErrorCode.pm | 15 +++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index 2554078..a04f11d 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ Revision history for {{$dist->name}} {{$NEXT}} + - Documentation improvements (gh#11) + - Added frame option to throw (gh#12) 0.02 2022-10-06 13:35:58 -0600 - Import will croak if you provide a bad option (gh#6, gh#7) diff --git a/README.md b/README.md index c8c8169..9534d16 100644 --- a/README.md +++ b/README.md @@ -138,12 +138,19 @@ The base class provides these attributes and methods: ## throw ```perl -Exception::FFI::ErrorCode::Base->throw( code => $code ); +Exception::FFI::ErrorCode::Base->throw( code => $code, %attr ); +Exception::FFI::ErrorCode::Base->throw( code => $code, frame => $frame, %attr ); ``` Throws the exception with the given code. Obviously you would throw the subclass, not the base class. +If you have added additional attributes via [Class::Tiny](https://metacpan.org/pod/Class::Tiny) you can provide them as +`%attr`. + +If you want the exception to appear to happen from a different frame then you can +specify it with `$frame`. + ## strerror ```perl diff --git a/lib/Exception/FFI/ErrorCode.pm b/lib/Exception/FFI/ErrorCode.pm index 8becfab..74c8a05 100644 --- a/lib/Exception/FFI/ErrorCode.pm +++ b/lib/Exception/FFI/ErrorCode.pm @@ -137,11 +137,18 @@ The base class provides these attributes and methods: =head2 throw - Exception::FFI::ErrorCode::Base->throw( code => $code ); + Exception::FFI::ErrorCode::Base->throw( code => $code, %attr ); + Exception::FFI::ErrorCode::Base->throw( code => $code, frame => $frame, %attr ); Throws the exception with the given code. Obviously you would throw the subclass, not the base class. +If you have added additional attributes via L you can provide them as +C<%attr>. + +If you want the exception to appear to happen from a different frame then you can +specify it with C<$frame>. + =head2 strerror my $string = $ex->strerror; @@ -299,9 +306,9 @@ and attached to all exceptions managed by L. }, bool => sub { 1 }, fallback => 1; - sub throw ($proto, @rest) + sub throw ($proto, %rest) { - my($package, $filename, $line) = caller; + my($package, $filename, $line) = caller( delete $rest{frame} // 0 ); my $self; if(is_blessed_ref $proto) @@ -314,7 +321,7 @@ and attached to all exceptions managed by L. else { $self = $proto->new( - @rest, + %rest, package => $package, filename => $filename, line => $line,