| 1 | package MR::IProto::Role::Debuggable; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | =head1 DESCRIPTION | ||||||||||
| 6 | |||||||||||
| 7 | =cut | ||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Mouse::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | =item debug | ||||||||||
| 12 | |||||||||||
| 13 | Deug level. | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | 1 | has debug => ( | |||||||||
| 18 | is => 'rw', | ||||||||||
| 19 | isa => 'Int', | ||||||||||
| 20 | default => 0, | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | =item debug_cb | ||||||||||
| 24 | |||||||||||
| 25 | Callback which is called when debug message is written. | ||||||||||
| 26 | |||||||||||
| 27 | =cut | ||||||||||
| 28 | |||||||||||
| 29 | 1 | has debug_cb => ( | |||||||||
| 30 | is => 'rw', | ||||||||||
| 31 | isa => 'CodeRef', | ||||||||||
| 32 | lazy_build => 1, | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | =item dump_no_ints | ||||||||||
| 36 | |||||||||||
| 37 | Skip print of integers in dump. | ||||||||||
| 38 | |||||||||||
| 39 | =cut | ||||||||||
| 40 | |||||||||||
| 41 | 1 | has dump_no_ints => ( | |||||||||
| 42 | is => 'ro', | ||||||||||
| 43 | isa => 'Bool', | ||||||||||
| 44 | ); | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub _build_debug_cb { | ||||||||
|
Subroutine
_build_debug_cb: not called CC=1 SCAR=6.9
| |||||||||||
| 47 | 0 | my ($self) = @_; | |||||||||
| 48 | 0 | my $prefix = ref $self; | |||||||||
| 49 | 0 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 50 | 0 | my ($msg) = @_; | |||||||||
| 51 | 0 | chomp $msg; | |||||||||
| 52 | 0 | warn sprintf "$prefix: $msg\n"; | |||||||||
| 53 | 0 | return; | |||||||||
| 54 | 0 | }; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub _debug { | ||||||||
|
Subroutine
_debug: not called CC=1 SCAR=6.9
| |||||||||||
| 58 | 0 | $_[0]->debug_cb->($_[1]); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub _debug_dump { | ||||||||
|
Subroutine
_debug_dump: not called CC=2 SCAR=17.9
| |||||||||||
| 62 | 0 | my ($self, $msg, $datum) = @_; | |||||||||
| 63 | 0 | ▶ | unless($self->dump_no_ints) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | $msg .= join(' ', unpack('L*', $datum)); | |||||||||
| 65 | 0 | $msg .= ' > '; | |||||||||
| 66 | } | ||||||||||
| 67 | 0 | $msg .= join(' ', map { sprintf "%02x", $_ } unpack("C*", $datum)); | |||||||||
| 68 | 0 | $self->_debug($msg); | |||||||||
| 69 | 0 | return; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 1 | ▶ | no Mouse::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 73 | |||||||||||
| 74 | 1 | 1; | |||||||||