File Coverage

blib/lib/Devel/CallerStack/Level.pm
Criterion Covered Total %
statement 32 40 80.0
branch 14 20 70.0
condition n/a
subroutine 7 8 87.5
pod 2 2 100.0
total 55 70 78.5


line stmt bran cond sub pod time code
1             package Devel::CallerStack::Level;
2 1     1   37595 use strict;
  1         3  
  1         44  
3 1     1   7 use warnings;
  1         6  
  1         41  
4 1     1   5 use Carp;
  1         6  
  1         411  
5              
6             our @CARP_NOT = ( __PACKAGE__ );
7              
8             our @ACCESSORS = qw/package filename line subroutine hasargs wantarray evaltext
9             is_require hints bitmask hinthash args/;
10              
11             sub new {
12 11     11 1 17 my $class = shift;
13 11         14 my ( $depth ) = @_;
14 11         26 my $self = bless( [], $class );
15             package DB;
16 11         87 my @caller = caller( $depth );
17 11 100       38 return unless @caller;
18 9 50       20 push @caller => undef unless @caller > 10;
19 9         39 @$self = ( @caller, [@DB::args] );
20 9         43 return $self;
21             }
22              
23             {
24             my $i = 0;
25             for my $accessor ( @ACCESSORS ) {
26             my $idx = $i++;
27             my $sub = sub {
28 56     56   108 my $self = shift;
29 56         94 for my $check ( @_ ) {
30 30 100       64 return unless $self->_check( $idx, $check );
31             }
32 45         426 return $self->[$idx];
33             };
34 1     1   6 no strict 'refs';
  1         1  
  1         434  
35             *$accessor = $sub;
36             }
37             }
38              
39             sub _check {
40 30     30   41 my $self = shift;
41 30         38 my ( $idx, $check ) = @_;
42 30         47 my $data = $self->[$idx];
43 30 100       686 if( !ref( $check )) {
    100          
    50          
44 20 100       143 return $data == $check if "$data$check" =~ m/^[\d\.e\-]+$/i;
45 8         59 return "$data" eq "$check";
46             }
47             elsif (ref($check) eq 'Regexp') {
48 5 100       39 return $data =~ $check ? 1 : 0;
49             }
50             elsif ( ref($check) eq 'CODE' ) {
51 5         21 return $check->( $data );
52             }
53             else {
54 0           croak( "Invalid check: $check" );
55             }
56             }
57              
58             sub check_ordered {
59 0     0 1   my $self = shift;
60 0           my $i = 0;
61 0           for my $check ( @_ ) {
62 0 0         next unless $self->_check( $i++, $check );
63 0 0         return unless wantarray;
64 0           return ( 0, $ACCESSORS[$i], $i );
65             }
66 0           return 1;
67             }
68              
69             1;
70              
71             __END__