File Coverage

inc/Test2/Util/Trace.pm
Criterion Covered Total %
statement 23 43 53.4
branch 3 8 37.5
condition n/a
subroutine 9 17 52.9
pod 10 12 83.3
total 45 80 56.2


line stmt bran cond sub pod time code
1             #line 1
2 6     6   40 package Test2::Util::Trace;
  6         11  
  6         165  
3 6     6   27 use strict;
  6         19  
  6         240  
4             use warnings;
5              
6             our $VERSION = '1.302073';
7              
8 6     6   46  
  6         13  
  6         251  
9             use Test2::Util qw/get_tid pkg_to_file/;
10 6     6   29  
  6         11  
  6         260  
11             use Carp qw/confess/;
12 6     6   3020  
  6         15  
  6         35  
13             use Test2::Util::HashBase qw{frame detail pid tid};
14              
15             sub init {
16 6 50   6 0 28 confess "The 'frame' attribute is required"
17             unless $_[0]->{+FRAME};
18 6 50       46  
19 6 50       33 $_[0]->{+PID} = $$ unless defined $_[0]->{+PID};
20             $_[0]->{+TID} = get_tid() unless defined $_[0]->{+TID};
21             }
22 9     9 0 27  
  9         136  
23             sub snapshot { bless {%{$_[0]}}, __PACKAGE__ };
24              
25 0     0 1 0 sub debug {
26 0 0       0 my $self = shift;
27 0         0 return $self->{+DETAIL} if $self->{+DETAIL};
28 0         0 my ($pkg, $file, $line) = $self->call;
29             return "at $file line $line";
30             }
31              
32 0     0 1 0 sub alert {
33 0         0 my $self = shift;
34 0         0 my ($msg) = @_;
35             warn $msg . ' ' . $self->debug . ".\n";
36             }
37              
38 0     0 1 0 sub throw {
39 0         0 my $self = shift;
40 0         0 my ($msg) = @_;
41             die $msg . ' ' . $self->debug . ".\n";
42             }
43 26     26 1 47  
  26         119  
44             sub call { @{$_[0]->{+FRAME}} }
45 18     18 1 79  
46 0     0 1   sub package { $_[0]->{+FRAME}->[0] }
47 0     0 1   sub file { $_[0]->{+FRAME}->[1] }
48 0     0 1   sub line { $_[0]->{+FRAME}->[2] }
49             sub subname { $_[0]->{+FRAME}->[3] }
50              
51 0     0 1   sub from_json {
52 0           my $class = shift;
53             my %p = @_;
54 0            
55 0           my $trace_pkg = delete $p{__PACKAGE__};
56             require(pkg_to_file($trace_pkg));
57 0            
58             return $trace_pkg->new(%p);
59             }
60              
61 0     0 1   sub TO_JSON {
62 0           my $self = shift;
63             return {%$self, __PACKAGE__ => ref $self};
64             }
65              
66             1;
67              
68             __END__