summaryrefslogtreecommitdiff
path: root/lib/PINGDOMFETCH/Display.pm
blob: 3838a82450a767e039030a50a7fbe89dc3dcdee2 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package PINGDOMFETCH::Display;

use strict;
use warnings;

use Data::Dumper;

use PINGDOMFETCH::Config;
use PINGDOMFETCH::Utils;

our $INDENT  = 0;
our $VERBOSE = 0;

use overload
  '""' => sub { shift->indents(); },
  '++' => sub { shift->inc(); },
  '--' => sub { shift->dec(); };

sub init {
    my ($self) = @_;

    $VERBOSE = $self->{'arg.verbose'} == 1;

    return undef;
}

sub inc {
    my ($self) = @_;

    return ++$INDENT;
}

sub dec {
    my ($self) = @_;

    return --$INDENT;
}

sub indents {
    my ($self) = @_;

    return ' ' x $INDENT;
}

sub display {
    my ( $self, $msging ) = @_;

    print $msging;

    return undef;
}

sub is_verbose {
    my ($self) = @_;

    return $VERBOSE == 1;
}

sub info_no_nl {
    my ( $self, $msg ) = @_;

    $self->display("$msg");

    return undef;
}

sub info {
    my ( $self, $msg, $notify ) = @_;

    my $str = "   $self $msg\n";

    $self->display($str);
    $notify->message_push($str) if defined $notify;

    return undef;
}

sub nl {
    my ( $self, $notify ) = @_;

    $self->display("\n");
    $notify->message_push("\n") if defined $notify;

    return undef;
}

sub error {
    my ( $self, $msg ) = @_;

    $self->display("!  ERROR: $self $msg\n");

    exit 666;

    return undef;
}

sub warning {
    my ( $self, $msg, $notify ) = @_;

    my $str = "!  $self $msg\n";

    $self->display($str);

    if ( defined $notify ) {
        $notify->message_push($str);
        $notify->{warnings}++;
    }

    return undef;
}

sub critical {
    my ( $self, $msg, $notify ) = @_;

    my $str = "!! $self $msg\n";

    $self->display($str);

    if ( defined $notify ) {
        $notify->message_push($str);
        $notify->{criticals}++;
    }

    return undef;
}

sub dump {
    my ( $self, $msg ) = @_;

    $self->display( Dumper $msg );

    return undef;
}

sub diedump {
    my ( $self, $msg ) = @_;

    die Dumper $msg;

    return undef;
}

sub verbose {
    my ( $self, $msg, $notify ) = @_;

    if ( $self->is_verbose() ) {
        my $str = "  $self $msg\n";

        $self->display($str);
        $notify->message_push($str) if defined $notify;
    }

    return undef;
}

1;