line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::LCDproc::Widget; |
2
|
|
|
|
|
|
|
$Net::LCDproc::Widget::VERSION = '0.104'; |
3
|
|
|
|
|
|
|
#ABSTRACT: Base class for all the widgets |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
589
|
use v5.10.2; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
6
|
1
|
|
|
1
|
|
4
|
use Log::Any qw($log); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
7
|
1
|
|
|
1
|
|
72
|
use Types::Standard qw/ArrayRef Bool InstanceOf Str/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
606
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
280
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has id => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => Str, |
14
|
|
|
|
|
|
|
required => 1, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has type => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => Str, |
20
|
|
|
|
|
|
|
traits => ['NoState'], |
21
|
|
|
|
|
|
|
default => sub { |
22
|
|
|
|
|
|
|
my $pkg = ref $_[0]; |
23
|
|
|
|
|
|
|
my @parts = split /::/, $pkg; |
24
|
|
|
|
|
|
|
return lc $parts[-1]; |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has frame_id => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
isa => Str, |
31
|
|
|
|
|
|
|
predicate => 'has_frame_id', |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#isa => 'Net::LCDproc::Widget::Frame', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has screen => ( |
37
|
|
|
|
|
|
|
is => 'rw', |
38
|
|
|
|
|
|
|
isa => InstanceOf ['Net::LCDproc::Screen'], |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has is_new => ( |
42
|
|
|
|
|
|
|
is => 'rw', |
43
|
|
|
|
|
|
|
isa => Bool, |
44
|
|
|
|
|
|
|
default => 1, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has changed => ( |
48
|
|
|
|
|
|
|
is => 'rw', |
49
|
|
|
|
|
|
|
isa => Bool, |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has _set_cmd => ( |
53
|
|
|
|
|
|
|
is => 'rw', |
54
|
|
|
|
|
|
|
isa => ArrayRef, |
55
|
|
|
|
|
|
|
required => 1, |
56
|
|
|
|
|
|
|
default => sub { [] }, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
### Public Methods |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub update { |
62
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ($self->is_new) { |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# needs to be added |
67
|
0
|
|
|
|
|
|
$self->_create_widget_on_server; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if (!$self->changed) { |
71
|
0
|
|
|
|
|
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
0
|
0
|
|
|
|
|
$log->debug('Updating widget: ' . $self->id) if $log->is_debug; |
74
|
0
|
|
|
|
|
|
my $cmd_str = $self->_get_set_cmd_str; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->screen->_lcdproc->_send_cmd($cmd_str); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->changed(0); |
79
|
0
|
|
|
|
|
|
return 1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# removes this widget from the LCDproc server, unhooks from $self->server, then destroys itself |
83
|
|
|
|
|
|
|
sub remove { |
84
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $cmd_str = sprintf 'widget_del %s %s', $self->screen->id, $self->id; |
87
|
0
|
|
|
|
|
|
$self->_lcdproc->_send_cmd($cmd_str); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return 1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
### Private Methods |
93
|
|
|
|
|
|
|
sub _get_set_cmd_str { |
94
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $cmd_str = sprintf 'widget_set %s %s', $self->screen->id, $self->id; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
foreach my $attr (@{$self->_set_cmd}) { |
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$cmd_str .= sprintf ' "%s"', $self->$attr; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
return $cmd_str; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _create_widget_on_server { |
107
|
0
|
|
|
0
|
|
|
my $self = shift; |
108
|
0
|
|
|
|
|
|
$log->debugf('Adding new widget: %s - %s', $self->id, $self->type); |
109
|
0
|
|
|
|
|
|
my $add_str = sprintf 'widget_add %s %s %s', |
110
|
|
|
|
|
|
|
$self->screen->id, $self->id, $self->type; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if ($self->has_frame_id) { |
113
|
0
|
|
|
|
|
|
$add_str .= " -in " . $self->frame_id; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
$self->screen->_lcdproc->_send_cmd($add_str); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$self->is_new(0); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# make sure it gets set |
120
|
0
|
|
|
|
|
|
$self->changed(1); |
121
|
0
|
|
|
|
|
|
return 1; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |