File: app_simple.pl

package info (click to toggle)
libnetsds-perl 1.301-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 1,516; makefile: 7
file content (68 lines) | stat: -rwxr-xr-x 1,327 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env perl 

=head1 SYNOPSIS

Options:

	--help - this message
	--version - show application version
	--verbose - increase verbosity level
	--daemon - run as daemon

C<app_simple.pl> is an example for NetSDS application developers.

=cut

use version; our $VERSION = "1.001";

MyApp->run(
	infinite    => 1,              # infinite loop
	daemon      => 0,              # not a daemon
	has_conf    => 0,              # no configuration
	verbose     => 1,              # verbose mode on
	use_pidfile => 1,
	edr_file    => './test.edr',
);

1;

package MyApp;

use 5.8.0;
use warnings;
use strict;

use lib '../lib';

# Inherits NetSDS::App features
use base 'NetSDS::App';

sub start {
	my ($this) = @_;
	print "Application started: name=" . $this->name . "\n";
	if ( $this->debug ) { print "We are under debug!\n"; }

	use Data::Structure::Util;
	my $zuka = Data::Structure::Util::signature($this);
	print "Z: $zuka\n";
}

sub process {
	my ($this) = @_;

	for ( my $i = 1 ; $i <= 3 ; $i++ ) {

		# Do something and add messages to syslog
		print "PID=" . $this->pid . "; iteration: $i\n";
		$this->log( "info", "My PID: " . $this->pid . "; iteration: $i" );
		$this->edr( { pid => $this->pid, iteration => $i } );
		sleep 1;
	}
}

sub stop {
	my ($this) = @_;
	print "Finishing application at last. Bye! :-)\n";
}

1;