annotate lib/IMPL/Debug.pm @ 425:c27434cdd611 ref20150831

sync
author cin
date Tue, 03 Apr 2018 19:30:01 +0300
parents b0481c071bea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
422
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
1 package IMPL::Debug;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
2 use strict;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
3 use warnings;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
4
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
5 our $ENABLE = 0;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
6 our %ENABLE;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
7
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
8 my %subscriptions;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
9 my @subscriptions;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
10
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
11 sub stub { }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
12
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
13 sub import {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
14 my ( $self, @args ) = @_;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
15
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
16 my $caller = caller;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
17 no strict 'refs';
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
18
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
19 my $enabled = exists $ENABLE{$caller} ? $ENABLE{$caller} : $ENABLE;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
20
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
21 *{"${caller}::dbg_log"} = $enabled
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
22 ? sub {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
23 $self->log( $caller, @_ );
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
24 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
25 : \&stub;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
26
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
27 *{"${caller}::dbg_error"} = $enabled
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
28 ? sub {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
29 $self->log( $caller, @_ );
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
30 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
31 : \&stub;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
32
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
33 *{"${caller}::dbg_warn"} = $enabled
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
34 ? sub {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
35 $self->log( $caller, @_ );
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
36 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
37 : \&stub;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
38 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
39
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
40 sub log {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
41 my $self = shift;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
42 my $channel = shift;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
43 $_->(@_) foreach @{ $subscriptions{$channel} || [] };
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
44 $_->(@_) foreach @subscriptions;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
45 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
46
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
47 sub subscribe {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
48 my ( $self, $channel, $callback ) = @_;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
49
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
50 if ( @_ == 2 ) {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
51 $callback = $channel;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
52 $channel = undef;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
53 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
54
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
55 die IMPL::InvalidArgumentException->new('callback')
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
56 unless ref $callback eq 'CODE';
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
57
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
58 if ($channel) {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
59 push @{ $subscriptions{$channel} }, $callback;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
60 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
61 else {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
62 push @subscriptions, $callback;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
63 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
64 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
65
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
diff changeset
66 1;