File: Debug.pm

package info (click to toggle)
libsql-translator-perl 0.11024-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,572 kB
  • sloc: perl: 67,471; sql: 3,809; xml: 258; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 815 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package SQL::Translator::Role::Debug;
use Moo::Role;
use Sub::Quote qw(quote_sub);

has _DEBUG => (
    is => 'rw',
    accessor => 'debugging',
    init_arg => 'debugging',
    coerce => quote_sub(q{ $_[0] ? 1 : 0 }),
    lazy => 1,
    builder => 1,
);

sub _build__DEBUG {
    my ($self) = @_;
    my $class = ref $self;
    no strict 'refs';
    return ${"${class}::DEBUG"};
}

around debugging => sub {
    my ($orig, $self) = (shift, shift);

    # Emulate horrible Class::Base API
    unless (ref $self) {
        my $dbgref = do { no strict 'refs'; \${"${self}::DEBUG"} };
        $$dbgref = $_[0] if @_;
        return $$dbgref;
    }
    return $self->$orig(@_);
};

sub debug {
    my $self = shift;

    return unless $self->debugging;

    print STDERR '[', (ref $self || $self), '] ', @_, "\n";
}

1;