| 1 | package Caller::Reverse; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | our $VERSION = '0.01'; | ||
| 8 | |||
| 9 | 1 | ▶ | use base 'Import::Export'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | our %EX = ( | ||
| 12 | caller_first => [qw/all/], | ||
| 13 | callr => [qw/all/], | ||
| 14 | ); | ||
| 15 | |||
| 16 | sub caller_first { | ||
| 17 | return callr(0, $_[0]); | ||
| 18 | } | ||
| 19 | |||
| 20 | sub callr { | ||
| 21 | my ($n, @caller) = 0; | ||
| 22 | while (my @l = (caller($n))) { | ||
| 23 | unshift @caller, \@l unless | ||
| 24 | $l[0] =~ m/Caller\:\:Reverse/ | ||
| 25 | or | ||
| 26 | !$_[1] && $l[0] =~ m/main/; | ||
| 27 | $n++; | ||
| 28 | } | ||
| 29 | return wantarray ? @{$caller[$_[0]]} : $caller[$_[0]][0]; | ||
| 30 | } | ||
| 31 | |||
| 32 | =head1 NAME | ||
| 33 | |||
| 34 | Caller::Reverse - reverse the caller stack. | ||
| 35 | |||
| 36 | =head1 VERSION | ||
| 37 | |||
| 38 | Version 0.01 | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | =head1 SYNOPSIS | ||
| 43 | |||
| 44 | use Caller::Reverse qw/callr caller_first/; | ||
| 45 | |||
| 46 | my @caller = caller_first(); | ||
| 47 | |||
| 48 | my @callr = callr(2); | ||
| 49 | |||
| 50 | =head1 DESCRIPTION | ||
| 51 | |||
| 52 | This is a quick module to return that reverses the caller stack. | ||
| 53 | |||
| 54 | =cut | ||
| 55 | |||
| 56 | =head1 EXPORT | ||
| 57 | |||
| 58 | A list of functions that can be exported. | ||
| 59 | |||
| 60 | =head2 caller_first | ||
| 61 | |||
| 62 | Returns the first caller from the stack. In scalar context this will return the package name and in list context you will get the full caller response. See L<https://perldoc.perl.org/functions/caller.html> for more information. | ||
| 63 | |||
| 64 | my $package = caller_first(); | ||
| 65 | my @caller = caller_first(); | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | =head2 callr | ||
| 70 | |||
| 71 | The reverse order of caller. | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | =head1 AUTHOR | ||
| 76 | |||
| 77 | LNATION, C<< <lnation at cpan.org> >> | ||
| 78 | |||
| 79 | =head1 BUGS | ||
| 80 | |||
| 81 | Please report any bugs or feature requests to C<bug-caller-reverse at rt.cpan.org>, or through | ||
| 82 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Caller-Reverse>. I will be notified, and then you'll | ||
| 83 | automatically be notified of progress on your bug as I make changes. | ||
| 84 | |||
| 85 | =head1 SUPPORT | ||
| 86 | |||
| 87 | You can find documentation for this module with the perldoc command. | ||
| 88 | |||
| 89 | perldoc Caller::Reverse | ||
| 90 | |||
| 91 | |||
| 92 | You can also look for information at: | ||
| 93 | |||
| 94 | =over 4 | ||
| 95 | |||
| 96 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 97 | |||
| 98 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Caller-Reverse> | ||
| 99 | |||
| 100 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 101 | |||
| 102 | L<http://annocpan.org/dist/Caller-Reverse> | ||
| 103 | |||
| 104 | =item * CPAN Ratings | ||
| 105 | |||
| 106 | L<https://cpanratings.perl.org/d/Caller-Reverse> | ||
| 107 | |||
| 108 | =item * Search CPAN | ||
| 109 | |||
| 110 | L<https://metacpan.org/release/Caller-Reverse> | ||
| 111 | |||
| 112 | =back | ||
| 113 | |||
| 114 | =head1 ACKNOWLEDGEMENTS | ||
| 115 | |||
| 116 | =head1 LICENSE AND COPYRIGHT | ||
| 117 | |||
| 118 | This software is Copyright (c) 2020 by LNATION. | ||
| 119 | |||
| 120 | This is free software, licensed under: | ||
| 121 | |||
| 122 | The Artistic License 2.0 (GPL Compatible) | ||
| 123 | |||
| 124 | =cut | ||
| 125 | |||
| 126 | 1; # End of Caller::Reverse | ||