Net-LCDproc
view release on metacpan or search on metacpan
lib/Net/LCDproc/Screen.pm view on Meta::CPAN
);
has is_new => (is => 'rw', isa => Bool, default => 1);
has _lcdproc => (is => 'rw', isa => InstanceOf['Net::LCDproc']);
has _state => (is => 'ro', isa => HashRef, default => sub {{}});
sub set {
my ($self, $attr, $val) = @_;
# set the attribute
my $setter = "_set_$attr";
$self->$setter($val);
# and record it is dirty
$self->_state->{$attr} = 1;
return 1;
}
# updates the screen on the server
sub update {
my $self = shift;
if ($self->is_new) {
# screen needs to be added
if ($log->is_debug) { $log->debug('Adding ' . $self->id) }
$self->_lcdproc->_send_cmd('screen_add ' . $self->id);
$self->is_new(0);
}
# even if the screen was new, we leave defaults up to the LCDproc server
# so nothing *has* to be set
foreach my $attr (keys %{$self->_state}) {
$log->debug('Updating screen: ' . $self->id) if $log->is_debug;
my $cmd_str = $self->_get_cmd_str_for($attr);
$self->_lcdproc->_send_cmd($cmd_str);
delete $self->_state->{$attr};
}
# now check the the widgets attached to this screen
foreach my $widget (@{$self->widgets}) {
$widget->update;
}
return 1;
}
# TODO accept an arrayref of widgets
sub add_widget {
my ($self, $widget) = @_;
$widget->screen($self);
push @{$self->widgets}, $widget;
return 1;
}
# removes screen from N::L, deletes from server, then cascades and kills its widgets (optionally not)
sub remove {
my ($self, $keep_widgets) = @_;
if (!defined $keep_widgets) {
foreach my $widget (@{$self->widgets}) {
$widget->remove;
}
}
return 1;
}
### Private Methods
sub _get_cmd_str_for {
my ($self, $attr) = @_;
my $cmd_str = 'screen_set ' . $self->id;
$cmd_str .= sprintf ' %s "%s"', $attr, $self->$attr;
return $cmd_str;
}
1;
__END__
=pod
=encoding UTF-8
=for :stopwords Ioan Rogers
=head1 NAME
Net::LCDproc::Screen - represents an LCDproc screen
=head1 VERSION
version 0.104
=head1 METHODS
=head2 C<set($attr, $val)>
Assign a new value to a screen attribute.
=head1 BUGS AND LIMITATIONS
You can make new bug reports, and view existing ones, through the
web interface at L<https://github.com/ioanrogers/Net-LCDproc/issues>.
=head1 AVAILABILITY
The project homepage is L<http://metacpan.org/release/Net-LCDproc/>.
The latest version of this module is available from the Comprehensive Perl
Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN
site near you, or see L<https://metacpan.org/module/Net::LCDproc/>.
=head1 SOURCE
( run in 0.666 second using v1.01-cache-2.11-cpan-39bf76dae61 )