| 1 | package Test2::Tools::Warnings; | ||||||||||
| 2 | 163 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 163 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 163 | our $VERSION = '1.302226'; | |||||||||
| 6 | |||||||||||
| 7 | 163 | ▶ | use Carp qw/carp/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 163 | ▶ | use Test2::API qw/context test2_add_pending_diag/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 163 | our @EXPORT = qw/warns warning warnings no_warnings/; | |||||||||
| 11 | 163 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 5 | ▶ | sub warns(&) { | ||||||||
|
Subroutine
warns: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 14 | 5 | my $code = shift; | |||||||||
| 15 | |||||||||||
| 16 | 5 | ▶ | defined wantarray or carp "Useless use of warns() in void context"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | |||||||||||
| 18 | 5 | my $warnings = 0; | |||||||||
| 19 | 5 | ▶ | local $SIG{__WARN__} = sub { $warnings++ }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 5 | $code->(); | |||||||||
| 21 | 5 | return $warnings; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 5 | ▶ | sub no_warnings(&) { | ||||||||
|
Subroutine
no_warnings: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 25 | 5 | ▶ | defined wantarray or carp "Useless use of no_warnings() in void context"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | 5 | my $warnings = &warnings(@_); | |||||||||
| 28 | 5 | ▶ | return 1 if !@$warnings; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | 3 | test2_add_pending_diag(@$warnings); | |||||||||
| 31 | |||||||||||
| 32 | 3 | return 0; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 20 | ▶ | sub warning(&) { | ||||||||
|
Subroutine
warning: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 36 | 20 | my $code = shift; | |||||||||
| 37 | |||||||||||
| 38 | 20 | ▶ | defined wantarray or carp "Useless use of warning() in void context"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | 20 | my @warnings; | |||||||||
| 41 | { | ||||||||||
| 42 | 20 | ▶ | local $SIG{__WARN__} = sub { push @warnings => @_ }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 20 | $code->(); | |||||||||
| 44 | 20 | ▶ | return unless @warnings; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 18 | ▶ | if (@warnings > 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 1 | my $ctx = context(); | |||||||||
| 49 | 1 | $ctx->alert("Extra warnings in warning { ... }"); | |||||||||
| 50 | 1 | $ctx->note($_) for @warnings; | |||||||||
| 51 | 1 | $ctx->release; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 18 | return $warnings[0]; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 15 | ▶ | sub warnings(&) { | ||||||||
|
Subroutine
warnings: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 58 | 15 | my $code = shift; | |||||||||
| 59 | |||||||||||
| 60 | 15 | ▶ | defined wantarray or carp "Useless use of warnings() in void context"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 15 | my @warnings; | |||||||||
| 63 | 15 | ▶ | local $SIG{__WARN__} = sub { push @warnings => @_ }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 15 | $code->(); | |||||||||
| 65 | |||||||||||
| 66 | 15 | return \@warnings; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 163 | 1; | |||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | __END__ | ||||||||||