Util-Underscore

 view release on metacpan or  search on metacpan

lib/Util/Underscore/CallStackFrame.pm  view on Meta::CPAN

package Util::Underscore::CallStackFrame;

#ABSTRACT: object-oriented wrapper for "caller" builtin

use strict;
use warnings;

use Carp ();

## no critic (RequireFinalReturn)
# reason: performance and terse code.
# All methods are supposed to return something.

## no critic (ProhibitMagicNumbers)
# reason: the "caller" builtin is full of magic numbers.
# This class wraps them so that users don't have to deal with them.


sub of {
    my ($class, $level) = @_;

    package DB;    ## no critic (ProhibitMUltiplePackages)
    my @caller = CORE::caller($level + 1);
    return if not @caller;
    push @caller, [@DB::args];    ## no critic (ProhibitPackageVars)
    return bless \@caller => $class;
}


## no critic (ProhibitBuiltinHomonyms)
sub package { shift()->[0] }


sub file { shift()->[1] }


sub line { shift()->[2] }


sub subroutine { shift()->[3] }


sub has_args {
    my ($self) = @_;
    $self->[4] && $self->[11];
}


sub wantarray { shift()->[5] }


sub is_eval {
    my ($self) = @_;
    if ($self->[3] eq '(eval)') {
        my $accessor_object = [ @{$self}[ 6, 7 ] ];
        bless $accessor_object => 'Util::Underscore::CallStackFrame::_Eval';
        return $accessor_object;
    }
    else {
        return !!0;
    }
}

{
    ## no critic (ProhibitMUltiplePackages)
    package Util::Underscore::CallStackFrame::_Eval;

    sub source { shift()->[0] }

    sub is_require { shift()->[1] }
}


sub is_require { shift()->[7] }


sub hints { shift()->[8] }


sub bitmask { shift()->[9] }


sub hinthash { shift()->[10] }

1;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.466 second using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )