| 1 | |||||||||||||||||||||||||||||
| 2 | package WebService::Rollbar::Notifier; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '1.002011'; # VERSION | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Mojo::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # HTTPS for some reason fails on Solaris, based on smoker tests | ||||||||||||||||||||||||||||
| 15 | 2 | ▶ | my $API_URL = ($^O eq 'solaris'?'http':'https').'://api.rollbar.com/api/1/'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | has _ua => sub { Mojo::UserAgent->new; }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | has callback => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | ## Null by default, but not undef, because undef for callback | ||||||||||||||||||||||||||||
| 20 | ## means we want to block | ||||||||||||||||||||||||||||
| 21 | 2 | }; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | has environment => 'production'; | |||||||||||||||||||||||||||
| 24 | 2 | has [ qw/access_token code_version framework language server/ ]; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub critical { my $self = shift; $self->notify( 'critical', @_ ); } | ||||||||||||||||||||||||||
|
Subroutine
critical: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub error { my $self = shift; $self->notify( 'error', @_ ); } | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub warning { my $self = shift; $self->notify( 'warning', @_ ); } | ||||||||||||||||||||||||||
|
Subroutine
warning: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub info { my $self = shift; $self->notify( 'info', @_ ); } | ||||||||||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub debug { my $self = shift; $self->notify( 'debug', @_ ); } | ||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub _parse_message_param { | ||||||||||||||||||||||||||
|
Subroutine
_parse_message_param: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 33 | 0 | my $message = shift; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if (ref($message) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return ($message->[0], $message->[1]||{}); | ||||||||||||||||||||||||||
|
Condition0%0/2
$message->[1] || {}
MC/DC0%0/1
$message->[1] || {}
$message->[1]
Truth table0%0/2
A
A= $message->[1]
| |||||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||
| 38 | 0 | return ($message, {} ); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub report_message { | ||||||||||||||||||||||||||
|
Subroutine
report_message: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($self) = shift; | |||||||||||||||||||||||||||
| 43 | 0 | my ($message, $request_params) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my ($body, $custom) = _parse_message_param($message); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | return $self->_post( | ||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | message => { | ||||||||||||||||||||||||||||
| 50 | body => $body, | ||||||||||||||||||||||||||||
| 51 | 0 | %{ $custom }, | |||||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||
| 54 | $request_params, | ||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub notify { | ||||||||||||||||||||||||||
|
Subroutine
notify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | 0 | my ( $severity, $message, $custom ) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | return $self->report_message( [$message, $custom], {level => $severity} ); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | my @frame_optional_fields = | |||||||||||||||||||||||||||
| 67 | qw/lineno colno method code context argspec varargspec keywordspec locals / | ||||||||||||||||||||||||||||
| 68 | ; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub _parse_exception_params { | ||||||||||||||||||||||||||
|
Subroutine
_parse_exception_params: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 71 | 0 | my @params = @_; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $request_params = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | ref $params[-1] eq 'HASH' | ||||||||||||||||||||||||||||
| 75 | ? pop @params | ||||||||||||||||||||||||||||
| 76 | : {} | ||||||||||||||||||||||||||||
| 77 | ; | ||||||||||||||||||||||||||||
| 78 | 0 | my $frames = _extract_frames(pop @params); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | my ($class, $message, $description) = @params; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | return ( | ||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | class => $class, | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 85 | (defined $message ? (message => $message) : ()), | ||||||||||||||||||||||||||||
| 86 | (defined $description ? (description => $description) : ()), | ||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||
| 88 | $frames, | ||||||||||||||||||||||||||||
| 89 | $request_params, | ||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub _devel_stacktrace_frame_to_rollbar { | ||||||||||||||||||||||||||
|
Subroutine
_devel_stacktrace_frame_to_rollbar: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 93 | 0 | my $frame = shift; | |||||||||||||||||||||||||||
| 94 | return { | ||||||||||||||||||||||||||||
| 95 | 0 | filename => $frame->filename, | |||||||||||||||||||||||||||
| 96 | lineno => $frame->line, | ||||||||||||||||||||||||||||
| 97 | method => $frame->subroutine, | ||||||||||||||||||||||||||||
| 98 | # code | ||||||||||||||||||||||||||||
| 99 | # context {} | ||||||||||||||||||||||||||||
| 100 | # varargspec: args | ||||||||||||||||||||||||||||
| 101 | # locals: { args => ... } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub _extract_frames { | ||||||||||||||||||||||||||
|
Subroutine
_extract_frames: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 105 | 0 | my $trace = shift; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( ref($trace) eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | # Assume rollbar-ready frames | ||||||||||||||||||||||||||||
| 109 | 0 | return $trace; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ( blessed($trace) and $trace->isa("Devel::StackTrace") ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($trace) and $trace->isa("Devel::StackTrace")
MC/DC0%0/2
builtin::blessed($trace) and $trace->isa("Devel::StackTrace")
builtin::blessed($trace)
$trace->isa("Devel::StackTrace")
Truth table0%0/3
A and B
A= builtin::blessed($trace)B= $trace->isa("Devel::StackTrace")
| |||||||||||||||||||||||||||||
| 112 | return [ | ||||||||||||||||||||||||||||
| 113 | 0 | map { _devel_stacktrace_frame_to_rollbar( $_ ) } | |||||||||||||||||||||||||||
| 114 | $trace->frames | ||||||||||||||||||||||||||||
| 115 | ]; | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | return (); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub report_trace { | ||||||||||||||||||||||||||
|
Subroutine
report_trace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | my ($exception_data, $frames, $request_params) = _parse_exception_params(@_); | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | return $self->_post( | |||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||
| 128 | trace => { | ||||||||||||||||||||||||||||
| 129 | exception => $exception_data, | ||||||||||||||||||||||||||||
| 130 | frames => $frames, | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | }, | ||||||||||||||||||||||||||||
| 133 | $request_params, | ||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub _post { | ||||||||||||||||||||||||||
|
Subroutine
_post: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 139 | 0 | my ( $body, $request_optionals ) = @_; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my @instance_optionals = ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | map +( defined $self->$_ ? ( $_ => $self->$_ ) : () ), | ||||||||||||||||||||||||||||
| 143 | qw/code_version framework language server/ | ||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||
| 145 | my @request_optionals = ( | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | map +( exists $request_optionals->{$_} ? ( $_ => $request_optionals->{$_} ) : () ), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | qw/level context request person server client custom fingerprint uuid title/ | ||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $response = $self->_ua->post( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | $API_URL . 'item/', | ||||||||||||||||||||||||||||
| 152 | json => { | ||||||||||||||||||||||||||||
| 153 | access_token => $self->access_token, | ||||||||||||||||||||||||||||
| 154 | data => { | ||||||||||||||||||||||||||||
| 155 | environment => $self->environment, | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | body => $body, | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | platform => $^O, | ||||||||||||||||||||||||||||
| 160 | timestamp => time(), | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | @instance_optionals, | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | context => scalar( caller 3 ), | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | @request_optionals, | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | notifier => { | ||||||||||||||||||||||||||||
| 169 | name => 'WebService::Rollbar::Notifier', | ||||||||||||||||||||||||||||
| 170 | version => $VERSION, | ||||||||||||||||||||||||||||
| 171 | }, | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | }, | ||||||||||||||||||||||||||||
| 174 | }, | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | ( $self->callback ? $self->callback : () ), | ||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | return $self->callback ? (1) : $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 2 | ' | |||||||||||||||||||||||||||
| 184 | "Most of you are familiar with the virtues of a programmer. | ||||||||||||||||||||||||||||
| 185 | There are three, of course: laziness, impatience, and hubris." | ||||||||||||||||||||||||||||
| 186 | -- Larry Wall | ||||||||||||||||||||||||||||
| 187 | '; | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | __END__ | ||||||||||||||||||||||||||||