File: Debug.pm

package info (click to toggle)
libsql-translator-perl 1.66-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,680 kB
  • sloc: perl: 67,870; sql: 4,150; xml: 258; makefile: 14
file content (41 lines) | stat: -rw-r--r-- 780 bytes parent folder | download
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;