Declaring the modules, constants, and variables

We first declare the packages we’re going to use. In addition to Net::Jabber and Win32::OLE, we’re going to use Getopt::Std, which affords us a comfortable way of accepting and parsing command-line options. We also want to use the strict pragma, which should keep us from making silly coding mistakes by not allowing undeclared variables and the like.

We specify Client on the usage declaration for the Net::Jabber package to specify what should be loaded. The package is a large and comprehensive set of modules, and only some of those are relevant for what we wish to do in the script—build and work with a Jabber client connection. Other module sets are pulled in by specifying Component or Server.

use Net::Jabber qw(Client);
use Win32::OLE;
use Getopt::Std;
use strict;

We’re going to allow the command-line options -l and -s, which perform the following tasks:

No options specified (or just the -s options): calibration mode.

When we run the script for the first time, we need to perform the calibration and read values from the sensor to determine a midpoint value. A number above the midpoint signifies the presence of light and therefore the absence of coffee; below signifies the absence of light and therefore the presence of coffee. This step is necessary because not every environment (ambient light, sensitivity of the light sensor, and so on) will be the same. The upper and lower values, representing lightness and darkness, respectively, ...

Get Programming Jabber now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.