.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "App::Info 3pm"
.TH App::Info 3pm "2020-01-23" "perl v5.30.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
App::Info \- Information about software packages on a system
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use App::Info::Category::FooApp;
\&
\& my $app = App::Info::Category::FooApp\->new;
\&
\& if ($app\->installed) {
\& print "App name: ", $app\->name, "\en";
\& print "Version: ", $app\->version, "\en";
\& print "Bin dir: ", $app\->bin_dir, "\en";
\& } else {
\& print "App not installed on your system. :\-(\en";
\& }
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
App::Info is an abstract base class designed to provide a generalized
interface for subclasses that provide meta data about software packages
installed on a system. The idea is that these classes can be used in Perl
application installers in order to determine whether software dependencies
have been fulfilled, and to get necessary meta data about those software
packages.
.PP
App::Info provides an event model for handling events triggered by App::Info
subclasses. The events are classified as \*(L"info\*(R", \*(L"error\*(R", \*(L"unknown\*(R", and
\&\*(L"confirm\*(R" events, and multiple handlers may be specified to handle any or all
of these event types. This allows App::Info clients to flexibly handle events
in any way they deem necessary. Implementing new event handlers is
straight-forward, and use the triggering of events by App::Info subclasses is
likewise kept easy-to-use.
.PP
A few sample subclasses are provided with the distribution, but
others are invited to write their own subclasses and contribute them to the
\&\s-1CPAN.\s0 Contributors are welcome to extend their subclasses to provide more
information relevant to the application for which data is to be provided (see
App::Info::HTTPD::Apache for an example), but are
encouraged to, at a minimum, implement the abstract methods defined here and
in the category abstract base classes (e.g.,
App::Info::HTTPD and App::Info::Lib).
See Subclassing for more information on implementing new
subclasses.
.SH "INTERFACE"
.IX Header "INTERFACE"
This section documents the public interface of App::Info.
.SS "Constructor"
.IX Subsection "Constructor"
\fInew\fR
.IX Subsection "new"
.PP
.Vb 1
\& my $app = App::Info::Category::FooApp\->new(@params);
.Ve
.PP
Constructs an App::Info object and returns it. The \f(CW@params\fR arguments define
attributes that can be used to help the App::Info object search for
application information on the file system, as well as how the App::Info
object will respond to certain events. The event parameters correspond to
their like-named methods. See the \*(L"Event Handler Object Methods\*(R" section
for more information on App::Info events and how to handle them. The search
parameters that can be passed to \f(CW\*(C`new()\*(C'\fR are:
.IP "search_exe_names" 4
.IX Item "search_exe_names"
An array reference of possible names for binary executables. These may be used
by subclasses to search for application programs that can be used to retrieve
application information, such as version numbers. The subclasses generally
provide reasonable defaults for most cases.
.IP "search_bin_dirs" 4
.IX Item "search_bin_dirs"
An array reference of local directories in which to search for executables.
These may be used to search for the value of the \f(CW\*(C`bin_dir\*(C'\fR attribute in
addition to and in preference to the defaults used by each subclass.
.IP "search_lib_names" 4
.IX Item "search_lib_names"
An array reference of possible names for library files. These may be used by
subclasses to search for library files for the application. The subclasses
generally provide reasonable defaults for most cases.
.IP "search_so_lib_names" 4
.IX Item "search_so_lib_names"
An array reference of possible names for shared object library files. These
may be used by subclasses to search for shared object library files for the
application. The subclasses generally provide reasonable defaults for most
cases.
.IP "search_lib_dirs" 4
.IX Item "search_lib_dirs"
An array reference of local directories in which to search for libraries.
These may be used to search for the value of the \f(CW\*(C`lib_dir\*(C'\fR and \f(CW\*(C`so_lib_dir\*(C'\fR
attributes in addition to and in preference to the defaults used by each
subclass.
.IP "search_inc_names" 4
.IX Item "search_inc_names"
An array reference of possible names for include files. These may be used by
subclasses to search for include files for the application. The subclasses
generally provide reasonable defaults for most cases.
.IP "search_inc_dirs" 4
.IX Item "search_inc_dirs"
An array reference of local directories in which to search for include
files. These may be used to search for the value of the \f(CW\*(C`inc_dir\*(C'\fR attribute
in addition to and in preference to the defaults used by each subclass.
.PP
The parameters to \f(CW\*(C`new()\*(C'\fR for the different types of App::Info events are:
.IP "on_info" 4
.IX Item "on_info"
.PD 0
.IP "on_error" 4
.IX Item "on_error"
.IP "on_unknown" 4
.IX Item "on_unknown"
.IP "on_confirm" 4
.IX Item "on_confirm"
.PD
.PP
When passing event handlers to \f(CW\*(C`new()\*(C'\fR, the list of handlers for each type
should be an anonymous array, for example:
.PP
.Vb 1
\& my $app = App::Info::Category::FooApp\->new( on_info => \e@handlers );
.Ve
.SS "Meta Data Object Methods"
.IX Subsection "Meta Data Object Methods"
These are abstract methods in App::Info and must be provided by its
subclasses. They provide the essential meta data of the software package
supported by the App::Info subclass.
.PP
\fIkey_name\fR
.IX Subsection "key_name"
.PP
.Vb 1
\& my $key_name = $app\->key_name;
.Ve
.PP
Returns a string that uniquely identifies the software for which the App::Info
subclass provides data. This value should be unique across all App::Info
classes. Typically, it's simply the name of the software.
.PP
\fIinstalled\fR
.IX Subsection "installed"
.PP
.Vb 5
\& if ($app\->installed) {
\& print "App is installed.\en"
\& } else {
\& print "App is not installed.\en"
\& }
.Ve
.PP
Returns a true value if the application is installed, and a false value if it
is not.
.PP
\fIname\fR
.IX Subsection "name"
.PP
.Vb 1
\& my $name = $app\->name;
.Ve
.PP
Returns the name of the application.
.PP
\fIversion\fR
.IX Subsection "version"
.PP
.Vb 1
\& my $version = $app\->version;
.Ve
.PP
Returns the full version number of the application.
.PP
\fImajor_version\fR
.IX Subsection "major_version"
.PP
.Vb 1
\& my $major_version = $app\->major_version;
.Ve
.PP
Returns the major version number of the application. For example, if
\&\f(CW\*(C`version()\*(C'\fR returns \*(L"7.1.2\*(R", then this method returns \*(L"7\*(R".
.PP
\fIminor_version\fR
.IX Subsection "minor_version"
.PP
.Vb 1
\& my $minor_version = $app\->minor_version;
.Ve
.PP
Returns the minor version number of the application. For example, if
\&\f(CW\*(C`version()\*(C'\fR returns \*(L"7.1.2\*(R", then this method returns \*(L"1\*(R".
.PP
\fIpatch_version\fR
.IX Subsection "patch_version"
.PP
.Vb 1
\& my $patch_version = $app\->patch_version;
.Ve
.PP
Returns the patch version number of the application. For example, if
\&\f(CW\*(C`version()\*(C'\fR returns \*(L"7.1.2\*(R", then this method returns \*(L"2\*(R".
.PP
\fIbin_dir\fR
.IX Subsection "bin_dir"
.PP
.Vb 1
\& my $bin_dir = $app\->bin_dir;
.Ve
.PP
Returns the full path the application's bin directory, if it exists.
.PP
\fIexecutable\fR
.IX Subsection "executable"
.PP
.Vb 1
\& my $executable = $app\->executable;
.Ve
.PP
Returns the full path the application's bin directory, if it exists.
.PP
\fIinc_dir\fR
.IX Subsection "inc_dir"
.PP
.Vb 1
\& my $inc_dir = $app\->inc_dir;
.Ve
.PP
Returns the full path the application's include directory, if it exists.
.PP
\fIlib_dir\fR
.IX Subsection "lib_dir"
.PP
.Vb 1
\& my $lib_dir = $app\->lib_dir;
.Ve
.PP
Returns the full path the application's lib directory, if it exists.
.PP
\fIso_lib_dir\fR
.IX Subsection "so_lib_dir"
.PP
.Vb 1
\& my $so_lib_dir = $app\->so_lib_dir;
.Ve
.PP
Returns the full path the application's shared library directory, if it
exists.
.PP
\fIhome_url\fR
.IX Subsection "home_url"
.PP
.Vb 1
\& my $home_url = $app\->home_url;
.Ve
.PP
The \s-1URL\s0 for the software's home page.
.PP
\fIdownload_url\fR
.IX Subsection "download_url"
.PP
.Vb 1
\& my $download_url = $app\->download_url;
.Ve
.PP
The \s-1URL\s0 for the software's download page.
.SS "Search Attributes"
.IX Subsection "Search Attributes"
These methods return lists of things to look for on the local file system when
searching for application programs, library files, and include files. They are
empty by default, since each subclass generally relies on its own settings,
but you can add your own as preferred search parameters by specifying them as
parameters to the \f(CW\*(C`new()\*(C'\fR constructor.
.PP
\fIexe_names\fR
.IX Subsection "exe_names"
.PP
.Vb 1
\& my @search_exe_names = $app\->search_exe_names;
.Ve
.PP
Returns a list of possible names for an executable. Typically used by the
\&\f(CW\*(C`new()\*(C'\fR constructor to search for an executable to execute and collect
application info.
.PP
\fIsearch_bin_dirs\fR
.IX Subsection "search_bin_dirs"
.PP
.Vb 1
\& my @search_bin_dirs = $app\->search_bin_dirs;
.Ve
.PP
Returns a list of possible directories in which to search an executable.
Typically used by the \f(CW\*(C`new()\*(C'\fR constructor to find an executable to execute
and collect application info. The found directory will also generally then
be returned by the \f(CW\*(C`bin_dir\*(C'\fR method.
.PP
\fIlib_names\fR
.IX Subsection "lib_names"
.PP
.Vb 1
\& my @search_lib_names = $app\->search_lib_names;
.Ve
.PP
Returns a list of possible names for library files. Typically used by the
\&\f(CW\*(C`lib_dir()\*(C'\fR method to find library files.
.PP
\fIso_lib_names\fR
.IX Subsection "so_lib_names"
.PP
.Vb 1
\& my @search_so_lib_names = $app\->search_so_lib_names;
.Ve
.PP
Returns a list of possible names for library files. Typically used by the
\&\f(CW\*(C`so_lib_dir()\*(C'\fR method to find shared object library files.
.PP
\fIsearch_lib_dirs\fR
.IX Subsection "search_lib_dirs"
.PP
.Vb 1
\& my @search_lib_dirs = $app\->search_lib_dirs;
.Ve
.PP
Returns a list of possible directories in which to search for libraries.
Typically used by the \f(CW\*(C`lib_dir()\*(C'\fR and \f(CW\*(C`so_lib_dir()\*(C'\fR methods to find
library files.
.PP
\fIinc_names\fR
.IX Subsection "inc_names"
.PP
.Vb 1
\& my @search_inc_names = $app\->search_inc_names;
.Ve
.PP
Returns a list of possible names for include files. Typically used by the
\&\f(CW\*(C`inc_dir()\*(C'\fR method to find include files.
.PP
\fIsearch_inc_dirs\fR
.IX Subsection "search_inc_dirs"
.PP
.Vb 1
\& my @search_inc_dirs = $app\->search_inc_dirs;
.Ve
.PP
Returns a list of possible directories in which to search for includes.
Typically used by the \f(CW\*(C`inc_dir()\*(C'\fR method to find include files.
.SS "Event Handler Object Methods"
.IX Subsection "Event Handler Object Methods"
These methods provide control over App::Info event handling. Events can be
handled by one or more objects of subclasses of App::Info::Handler. The first
to return a true value will be the last to execute. This approach allows
handlers to be stacked, and makes it relatively easy to create new handlers.
App::Info::Handler for information on writing event
handlers.
.PP
Each of the event handler methods takes a list of event handlers as its
arguments. If none are passed, the existing list of handlers for the relevant
event type will be returned. If new handlers are passed in, they will be
returned.
.PP
The event handlers may be specified as one or more objects of the
App::Info::Handler class or subclasses, as one or more strings that tell
App::Info construct such handlers itself, or a combination of the two. The
strings can only be used if the relevant App::Info::Handler subclasses have
registered strings with App::Info. For example, the App::Info::Handler::Print
class included in the App::Info distribution registers the strings \*(L"stderr\*(R"
and \*(L"stdout\*(R" when it starts up. These strings may then be used to tell
App::Info to construct App::Info::Handler::Print objects that print to \s-1STDERR\s0
or to \s-1STDOUT,\s0 respectively. See the App::Info::Handler subclasses for what
strings they register with App::Info.
.PP
\fIon_info\fR
.IX Subsection "on_info"
.PP
.Vb 2
\& my @handlers = $app\->on_info;
\& $app\->on_info(@handlers);
.Ve
.PP
Info events are triggered when the App::Info subclass wants to send an
informational status message. By default, these events are ignored, but a
common need is for such messages to simply print to \s-1STDOUT.\s0 Use the
App::Info::Handler::Print class included with the
App::Info distribution to have info messages print to \s-1STDOUT:\s0
.PP
.Vb 5
\& use App::Info::Handler::Print;
\& $app\->on_info(\*(Aqstdout\*(Aq);
\& # Or:
\& my $stdout_handler = App::Info::Handler::Print\->new(\*(Aqstdout\*(Aq);
\& $app\->on_info($stdout_handler);
.Ve
.PP
\fIon_error\fR
.IX Subsection "on_error"
.PP
.Vb 2
\& my @handlers = $app\->on_error;
\& $app\->on_error(@handlers);
.Ve
.PP
Error events are triggered when the App::Info subclass runs into an unexpected
but not fatal problem. (Note that fatal problems will likely throw an
exception.) By default, these events are ignored. A common way of handling
these events is to print them to \s-1STDERR,\s0 once again using the
App::Info::Handler::Print class included with the
App::Info distribution:
.PP
.Vb 5
\& use App::Info::Handler::Print;
\& my $app\->on_error(\*(Aqstderr\*(Aq);
\& # Or:
\& my $stderr_handler = App::Info::Handler::Print\->new(\*(Aqstderr\*(Aq);
\& $app\->on_error($stderr_handler);
.Ve
.PP
Another approach might be to turn such events into fatal exceptions. Use the
included App::Info::Handler::Carp class for this
purpose:
.PP
.Vb 5
\& use App::Info::Handler::Carp;
\& my $app\->on_error(\*(Aqcroak\*(Aq);
\& # Or:
\& my $croaker = App::Info::Handler::Carp\->new(\*(Aqcroak\*(Aq);
\& $app\->on_error($croaker);
.Ve
.PP
\fIon_unknown\fR
.IX Subsection "on_unknown"
.PP
.Vb 2
\& my @handlers = $app\->on_unknown;
\& $app\->on_uknown(@handlers);
.Ve
.PP
Unknown events are triggered when the App::Info subclass cannot find the value
to be returned by a method call. By default, these events are ignored. A
common way of handling them is to have the application prompt the user for the
relevant data. The App::Info::Handler::Prompt class included with the
App::Info distribution can do just that:
.PP
.Vb 5
\& use App::Info::Handler::Prompt;
\& my $app\->on_unknown(\*(Aqprompt\*(Aq);
\& # Or:
\& my $prompter = App::Info::Handler::Prompt;
\& $app\->on_unknown($prompter);
.Ve
.PP
See App::Info::Handler::Prompt for information
on how it works.
.PP
\fIon_confirm\fR
.IX Subsection "on_confirm"
.PP
.Vb 2
\& my @handlers = $app\->on_confirm;
\& $app\->on_confirm(@handlers);
.Ve
.PP
Confirm events are triggered when the App::Info subclass has found an
important piece of information (such as the location of the executable it'll
use to collect information for the rest of its methods) and wants to confirm
that the information is correct. These events will most often be triggered
during the App::Info subclass object construction. Here, too, the
App::Info::Handler::Prompt class included with the App::Info distribution can
help out:
.PP
.Vb 5
\& use App::Info::Handler::Prompt;
\& my $app\->on_confirm(\*(Aqprompt\*(Aq);
\& # Or:
\& my $prompter = App::Info::Handler::Prompt;
\& $app\->on_confirm($prompter);
.Ve
.SH "SUBCLASSING"
.IX Header "SUBCLASSING"
As an abstract base class, App::Info is not intended to be used directly.
Instead, you'll use concrete subclasses that implement the interface it
defines. These subclasses each provide the meta data necessary for a given
software package, via the interface outlined above (plus any additional
methods the class author deems sensible for a given application).
.PP
This section describes the facilities App::Info provides for subclassing. The
goal of the App::Info design has been to make subclassing straight-forward, so
that developers can focus on gathering the data they need for their
application and minimize the work necessary to handle unknown values or to
confirm values. As a result, there are essentially three concepts that
developers need to understand when subclassing App::Info: organization,
utility methods, and events.
.SS "Organization"
.IX Subsection "Organization"
The organizational idea behind App::Info is to name subclasses by broad
software categories. This approach allows the categories themselves to
function as abstract base classes that extend App::Info, so that they can
specify more methods for all of their base classes to implement. For example,
App::Info::HTTPD has specified the \f(CW\*(C`httpd_root()\*(C'\fR abstract method that its
subclasses must implement. So as you get ready to implement your own subclass,
think about what category of software you're gathering information about.
New categories can be added as necessary.
.SS "Utility Methods"
.IX Subsection "Utility Methods"
Once you've decided on the proper category, you can start implementing your
App::Info concrete subclass. As you do so, take advantage of App::Info::Util,
wherein I've tried to encapsulate common functionality to make subclassing
easier. I found that most of what I was doing repetitively was looking for
files and directories, and searching through files. Thus, App::Info::Util
subclasses File::Spec in order to offer easy access to
commonly-used methods from that class, e.g., \f(CW\*(C`path()\*(C'\fR. Plus, it has several
of its own methods to assist you in finding files and directories in lists of
files and directories, as well as methods for searching through files and
returning the values found in those files. See
App::Info::Util for more information, and the App::Info
subclasses in this distribution for usage examples.
.PP
I recommend the use of a package-scoped lexical App::Info::Util object. That
way it's nice and handy when you need to carry out common tasks. If you find
you're doing something over and over that's not already addressed by an
App::Info::Util method, consider submitting a patch to App::Info::Util to add
the functionality you need.
.SS "Events"
.IX Subsection "Events"
Use the methods described below to trigger events. Events are designed to
provide a simple way for App::Info subclass developers to send status messages
and errors, to confirm data values, and to request a value when the class
cannot determine a value itself. Events may optionally be handled by module
users who assign App::Info::Handler subclass objects to your App::Info
subclass object using the event handling methods described in the \*(L"Event
Handler Object Methods\*(R" section.
.PP
\fIinfo\fR
.IX Subsection "info"
.PP
.Vb 1
\& $self\->info(@message);
.Ve
.PP
Use this method to display status messages for the user. You may wish to use
it to inform users that you're searching for a particular file, or attempting
to parse a file or some other resource for the data you need. For example, a
common use might be in the object constructor: generally, when an App::Info
object is created, some important initial piece of information is being
sought, such as an executable file. That file may be in one of many locations,
so it makes sense to let the user know that you're looking for it:
.PP
.Vb 1
\& $self\->info("Searching for executable");
.Ve
.PP
Note that, due to the nature of App::Info event handlers, your informational
message may be used or displayed any number of ways, or indeed not at all (as
is the default behavior).
.PP
The \f(CW@message\fR will be joined into a single string and stored in the
\&\f(CW\*(C`message\*(C'\fR attribute of the App::Info::Request object passed to info event
handlers.
.PP
\fIerror\fR
.IX Subsection "error"
.PP
.Vb 1
\& $self\->error(@error);
.Ve
.PP
Use this method to inform the user that something unexpected has happened. An
example might be when you invoke another program to parse its output, but it's
output isn't what you expected:
.PP
.Vb 1
\& $self\->error("Unable to parse version from \`/bin/myapp \-c\`");
.Ve
.PP
As with all events, keep in mind that error events may be handled in any
number of ways, or not at all.
.PP
The \f(CW@erorr\fR will be joined into a single string and stored in the \f(CW\*(C`message\*(C'\fR
attribute of the App::Info::Request object passed to error event handlers. If
that seems confusing, think of it as an \*(L"error message\*(R" rather than an \*(L"error
error.\*(R" :\-)
.PP
\fIunknown\fR
.IX Subsection "unknown"
.PP
.Vb 1
\& my $val = $self\->unknown(@params);
.Ve
.PP
Use this method when a value is unknown. This will give the user the option \*(--
assuming the appropriate handler handles the event \*(-- to provide the needed
data. The value entered will be returned by \f(CW\*(C`unknown()\*(C'\fR. The parameters are
as follows:
.IP "key" 4
.IX Item "key"
The \f(CW\*(C`key\*(C'\fR parameter uniquely identifies the data point in your class, and is
used by App::Info to ensure that an unknown event is handled only once, no
matter how many times the method is called. The same value will be returned by
subsequent calls to \f(CW\*(C`unknown()\*(C'\fR as was returned by the first call, and no
handlers will be activated. Typical values are \*(L"version\*(R" and \*(L"lib_dir\*(R".
.IP "prompt" 4
.IX Item "prompt"
The \f(CW\*(C`prompt\*(C'\fR parameter is the prompt to be displayed should an event handler
decide to prompt for the appropriate value. Such a prompt might be something
like \*(L"Path to your httpd executable?\*(R". If this parameter is not provided,
App::Info will construct one for you using your class' \f(CW\*(C`key_name()\*(C'\fR method
and the \f(CW\*(C`key\*(C'\fR parameter. The result would be something like \*(L"Enter a valid
FooApp version\*(R". The \f(CW\*(C`prompt\*(C'\fR parameter value will be stored in the
\&\f(CW\*(C`message\*(C'\fR attribute of the App::Info::Request object passed to event
handlers.
.IP "callback" 4
.IX Item "callback"
Assuming a handler has collected a value for your unknown data point, it might
make sense to validate the value. For example, if you prompt the user for a
directory location, and the user enters one, it makes sense to ensure that the
directory actually exists. The \f(CW\*(C`callback\*(C'\fR parameter allows you to do this. It
is a code reference that takes the new value or values as its arguments, and
returns true if the value is valid, and false if it is not. For the sake of
convenience, the first argument to the callback code reference is also stored
in \f(CW$_\fR .This makes it easy to validate using functions or operators that,
er, operate on \f(CW$_\fR by default, but still allows you to get more information
from \f(CW@_\fR if necessary. For the directory example, a good callback might be
\&\f(CW\*(C`sub { \-d }\*(C'\fR. The \f(CW\*(C`callback\*(C'\fR parameter code reference will be stored in the
\&\f(CW\*(C`callback\*(C'\fR attribute of the App::Info::Request object passed to event
handlers.
.IP "error" 4
.IX Item "error"
The error parameter is the error message to display in the event that the
\&\f(CW\*(C`callback\*(C'\fR code reference returns false. This message may then be used by the
event handler to let the user know what went wrong with the data she entered.
For example, if the unknown value was a directory, and the user entered a
value that the \f(CW\*(C`callback\*(C'\fR identified as invalid, a message to display might
be something like \*(L"Invalid directory path\*(R". Note that if the \f(CW\*(C`error\*(C'\fR
parameter is not provided, App::Info will supply the generic error message
\&\*(L"Invalid value\*(R". This value will be stored in the \f(CW\*(C`error\*(C'\fR attribute of the
App::Info::Request object passed to event handlers.
.PP
This may be the event method you use most, as it should be called in every
meta data method if you cannot provide the data needed by that method. It will
typically be the last part of the method. Here's an example demonstrating each
of the above arguments:
.PP
.Vb 4
\& my $dir = $self\->unknown( key => \*(Aqlib_dir\*(Aq,
\& prompt => "Enter lib directory path",
\& callback => sub { \-d },
\& error => "Not a directory");
.Ve
.PP
\fIconfirm\fR
.IX Subsection "confirm"
.PP
.Vb 1
\& my $val = $self\->confirm(@params);
.Ve
.PP
This method is very similar to \f(CW\*(C`unknown()\*(C'\fR, but serves a different purpose.
Use this method for significant data points where you've found an appropriate
value, but want to ensure it's really the correct value. A \*(L"significant data
point\*(R" is usually a value essential for your class to collect meta data values.
For example, you might need to locate an executable that you can then call to
collect other data. In general, this will only happen once for an object \*(--
during object construction \*(-- but there may be cases in which it is needed
more than that. But hopefully, once you've confirmed in the constructor that
you've found what you need, you can use that information to collect the data
needed by all of the meta data methods and can assume that they'll be right
because that first, significant data point has been confirmed.
.PP
Other than where and how often to call \f(CW\*(C`confirm()\*(C'\fR, its use is quite similar
to that of \f(CW\*(C`unknown()\*(C'\fR. Its parameters are as follows:
.IP "key" 4
.IX Item "key"
Same as for \f(CW\*(C`unknown()\*(C'\fR, a string that uniquely identifies the data point in
your class, and ensures that the event is handled only once for a given key.
The same value will be returned by subsequent calls to \f(CW\*(C`confirm()\*(C'\fR as was
returned by the first call for a given key.
.IP "prompt" 4
.IX Item "prompt"
Same as for \f(CW\*(C`unknown()\*(C'\fR. Although \f(CW\*(C`confirm()\*(C'\fR is called to confirm a value,
typically the prompt should request the relevant value, just as for
\&\f(CW\*(C`unknown()\*(C'\fR. The difference is that the handler \fIshould\fR use the \f(CW\*(C`value\*(C'\fR
parameter as the default should the user not provide a value. The \f(CW\*(C`prompt\*(C'\fR
parameter will be stored in the \f(CW\*(C`message\*(C'\fR attribute of the App::Info::Request
object passed to event handlers.
.IP "value" 4
.IX Item "value"
The value to be confirmed. This is the value you've found, and it will be
provided to the user as the default option when they're prompted for a new
value. This value will be stored in the \f(CW\*(C`value\*(C'\fR attribute of the
App::Info::Request object passed to event handlers.
.IP "callback" 4
.IX Item "callback"
Same as for \f(CW\*(C`unknown()\*(C'\fR. Because the user can enter data to replace the
default value provided via the \f(CW\*(C`value\*(C'\fR parameter, you might want to validate
it. Use this code reference to do so. The callback will be stored in the
\&\f(CW\*(C`callback\*(C'\fR attribute of the App::Info::Request object passed to event
handlers.
.IP "error" 4
.IX Item "error"
Same as for \f(CW\*(C`unknown()\*(C'\fR: an error message to display in the event that a
value entered by the user isn't validated by the \f(CW\*(C`callback\*(C'\fR code reference.
This value will be stored in the \f(CW\*(C`error\*(C'\fR attribute of the App::Info::Request
object passed to event handlers.
.PP
Here's an example usage demonstrating all of the above arguments:
.PP
.Vb 5
\& my $exe = $self\->confirm( key => \*(Aqshell\*(Aq,
\& prompt => \*(AqPath to your shell?\*(Aq,
\& value => \*(Aq/bin/sh\*(Aq,
\& callback => sub { \-x },
\& error => \*(AqNot an executable\*(Aq);
.Ve
.SS "Event Examples"
.IX Subsection "Event Examples"
Below I provide some examples demonstrating the use of the event methods.
These are meant to emphasize the contexts in which it's appropriate to use
them.
.PP
Let's start with the simplest, first. Let's say that to find the version
number for an application, you need to search a file for the relevant data.
Your App::Info concrete subclass might have a private method that handles this
work, and this method is the appropriate place to use the \f(CW\*(C`info()\*(C'\fR and, if
necessary, \f(CW\*(C`error()\*(C'\fR methods.
.PP
.Vb 2
\& sub _find_version {
\& my $self = shift;
\&
\& # Try to find the revelant file. We cover this method below.
\& # Just return if we cant\*(Aq find it.
\& my $file = $self\->_find_file(\*(Aqversion.conf\*(Aq) or return;
\&
\& # Send a status message.
\& $self\->info("Searching \*(Aq$file\*(Aq file for version");
\&
\& # Search the file. $util is an App::Info::Util object.
\& my $ver = $util\->search_file($file, qr/^Version\es+(.*)$/);
\&
\& # Trigger an error message, if necessary. We really think we\*(Aqll have the
\& # value, but we have to cover our butts in the unlikely event that we\*(Aqre
\& # wrong.
\& $self\->error("Unable to find version in file \*(Aq$file\*(Aq") unless $ver;
\&
\& # Return the version number.
\& return $ver;
\& }
.Ve
.PP
Here we've used the \f(CW\*(C`info()\*(C'\fR method to display a status message to let the
user know what we're doing. Then we used the \f(CW\*(C`error()\*(C'\fR method when something
unexpected happened, which in this case was that we weren't able to find the
version number in the file.
.PP
Note the \f(CW\*(C`_find_file()\*(C'\fR method we've thrown in. This might be a method that
we call whenever we need to find a file that might be in one of a list of
directories. This method, too, will be an appropriate place for an \f(CW\*(C`info()\*(C'\fR
method call. But rather than call the \f(CW\*(C`error()\*(C'\fR method when the file can't be
found, you might want to give an event handler a chance to supply that value
for you. Use the \f(CW\*(C`unknown()\*(C'\fR method for a case such as this:
.PP
.Vb 2
\& sub _find_file {
\& my ($self, $file) = @_;
\&
\& # Send a status message.
\& $self\->info("Searching for \*(Aq$file\*(Aq file");
\&
\& # Look for the file. See App::Info:Utility for its interface.
\& my @paths = qw(/usr/conf /etc/conf /foo/conf);
\& my $found = $util\->first_cat_path($file, @paths);
\&
\& # If we didn\*(Aqt find it, trigger an unknown event to
\& # give a handler a chance to get the value.
\& $found ||= $self\->unknown( key => "file_$file",
\& prompt => "Location of \*(Aq$file\*(Aq file?",
\& callback => sub { \-f },
\& error => "Not a file");
\&
\& # Now return the file name, regardless of whether we found it or not.
\& return $found;
\& }
.Ve
.PP
Note how in this method, we've tried to locate the file ourselves, but if we
can't find it, we trigger an unknown event. This allows clients of our
App::Info subclass to try to establish the value themselves by having an
App::Info::Handler subclass handle the event. If a value is found by an
App::Info::Handler subclass, it will be returned by \f(CW\*(C`unknown()\*(C'\fR and we can
continue. But we can't assume that the unknown event will even be handled, and
thus must expect that an unknown value may remain unknown. This is why the
\&\f(CW\*(C`_find_version()\*(C'\fR method above simply returns if \f(CW\*(C`_find_file()\*(C'\fR doesn't
return a file name; there's no point in searching through a file that doesn't
exist.
.PP
Attentive readers may be left to wonder how to decide when to use \f(CW\*(C`error()\*(C'\fR
and when to use \f(CW\*(C`unknown()\*(C'\fR. To a large extent, this decision must be based
on one's own understanding of what's most appropriate. Nevertheless, I offer
the following simple guidelines: Use \f(CW\*(C`error()\*(C'\fR when you expect something to
work and then it just doesn't (as when a file exists and should contain the
information you seek, but then doesn't). Use \f(CW\*(C`unknown()\*(C'\fR when you're less
sure of your processes for finding the value, and also for any of the values
that should be returned by any of the meta data object methods. And of course, \f(CW\*(C`error()\*(C'\fR would be more appropriate when you
encounter an unexpected condition and don't think that it could be handled in
any other way.
.PP
Now, more than likely, a method such \f(CW\*(C`_find_version()\*(C'\fR would be called by the
\&\f(CW\*(C`version()\*(C'\fR method, which is a meta data method mandated by the App::Info
abstract base class. This is an appropriate place to handle an unknown version
value. Indeed, every one of your meta data methods should make use of the
\&\f(CW\*(C`unknown()\*(C'\fR method. The \f(CW\*(C`version()\*(C'\fR method then should look something like
this:
.PP
.Vb 2
\& sub version {
\& my $self = shift;
\&
\& unless (exists $self\->{version}) {
\& # Try to find the version number.
\& $self\->{version} = $self\->_find_version ||
\& $self\->unknown( key => \*(Aqversion\*(Aq,
\& prompt => "Enter the version number");
\& }
\&
\& # Now return the version number.
\& return $self\->{version};
\& }
.Ve
.PP
Note how this method only tries to find the version number once. Any
subsequent calls to \f(CW\*(C`version()\*(C'\fR will return the same value that was returned
the first time it was called. Of course, thanks to the \f(CW\*(C`key\*(C'\fR parameter in the
call to \f(CW\*(C`unknown()\*(C'\fR, we could have have tried to enumerate the version number
every time, as \f(CW\*(C`unknown()\*(C'\fR will return the same value every time it is called
(as, indeed, should \f(CW\*(C`_find_version()\*(C'\fR. But by checking for the \f(CW\*(C`version\*(C'\fR key
in \f(CW$self\fR ourselves, we save some of the overhead.
.PP
But as I said before, every meta data method should make use of the
\&\f(CW\*(C`unknown()\*(C'\fR method. Thus, the \f(CW\*(C`major()\*(C'\fR method might looks something like
this:
.PP
.Vb 2
\& sub major {
\& my $self = shift;
\&
\& unless (exists $self\->{major}) {
\& # Try to get the major version from the full version number.
\& ($self\->{major}) = $self\->version =~ /^(\ed+)\e./;
\& # Handle an unknown value.
\& $self\->{major} = $self\->unknown( key => \*(Aqmajor\*(Aq,
\& prompt => "Enter major version",
\& callback => sub { /^\ed+$/ },
\& error => "Not a number")
\& unless defined $self\->{major};
\& }
\&
\& return $self\->{version};
\& }
.Ve
.PP
Finally, the \f(CW\*(C`confirm()\*(C'\fR method should be used to verify core pieces of data
that significant numbers of other methods rely on. Typically such data are
executables or configuration files from which will be drawn other meta data.
Most often, such major data points will be sought in the object constructor.
Here's an example:
.PP
.Vb 3
\& sub new {
\& # Construct the object so that handlers will work properly.
\& my $self = shift\->SUPER::new(@_);
\&
\& # Try to find the executable.
\& $self\->info("Searching for executable");
\& if (my $exe = $util\->first_exe(\*(Aq/bin/myapp\*(Aq, \*(Aq/usr/bin/myapp\*(Aq)) {
\& # Confirm it.
\& $self\->{exe} =
\& $self\->confirm( key => \*(Aqbinary\*(Aq,
\& prompt => \*(AqPath to your executable?\*(Aq,
\& value => $exe,
\& callback => sub { \-x },
\& error => \*(AqNot an executable\*(Aq);
\& } else {
\& # Handle an unknown value.
\& $self\->{exe} =
\& $self\->unknown( key => \*(Aqbinary\*(Aq,
\& prompt => \*(AqPath to your executable?\*(Aq,
\& callback => sub { \-x },
\& error => \*(AqNot an executable\*(Aq);
\& }
\&
\& # We\*(Aqre done.
\& return $self;
\& }
.Ve
.PP
By now, most of what's going on here should be quite familiar. The use of the
\&\f(CW\*(C`confirm()\*(C'\fR method is quite similar to that of \f(CW\*(C`unknown()\*(C'\fR. Really the only
difference is that the value is known, but we need verification or a new value
supplied if the value we found isn't correct. Such may be the case when
multiple copies of the executable have been installed on the system, we found
\&\fI/bin/myapp\fR, but the user may really be interested in \fI/usr/bin/myapp\fR.
Thus the \f(CW\*(C`confirm()\*(C'\fR event gives the user the chance to change the value if
the confirm event is handled.
.PP
The final thing to note about this constructor is the first line:
.PP
.Vb 1
\& my $self = shift\->SUPER::new(@_);
.Ve
.PP
The first thing an App::Info subclass should do is execute this line to allow
the super class to construct the object first. Doing so allows any event
handling arguments to set up the event handlers, so that when we call
\&\f(CW\*(C`confirm()\*(C'\fR or \f(CW\*(C`unknown()\*(C'\fR the event will be handled as the client expects.
.PP
If we needed our subclass constructor to take its own parameter argument, the
approach is to specify the same \f(CW\*(C`key =\*(C'\fR \f(CW$arg\fR> syntax as is used by
App::Info's \f(CW\*(C`new()\*(C'\fR method. Say we wanted to allow clients of our App::Info
subclass to pass in a list of alternate executable locations for us to search.
Such an argument would most make sense as an array reference. So we specify
that the key be \f(CW\*(C`alt_paths\*(C'\fR and allow the user to construct an object like
this:
.PP
.Vb 1
\& my $app = App::Info::Category::FooApp\->new( alt_paths => \e@paths );
.Ve
.PP
This approach allows the super class constructor arguments to pass unmolested
(as long as we use unique keys!):
.PP
.Vb 2
\& my $app = App::Info::Category::FooApp\->new( on_error => \e@handlers,
\& alt_paths => \e@paths );
.Ve
.PP
Then, to retrieve these paths inside our \f(CW\*(C`new()\*(C'\fR constructor, all we need do
is access them directly from the object:
.PP
.Vb 2
\& my $self = shift\->SUPER::new(@_);
\& my $alt_paths = $self\->{alt_paths};
.Ve
.SS "Subclassing Guidelines"
.IX Subsection "Subclassing Guidelines"
To summarize, here are some guidelines for subclassing App::Info.
.IP "\(bu" 4
Always subclass an App::Info category subclass. This will help to keep the
App::Info name space well-organized. New categories can be added as needed.
.IP "\(bu" 4
When you create the \f(CW\*(C`new()\*(C'\fR constructor, always call \f(CW\*(C`SUPER::new(@_)\*(C'\fR. This
ensures that the event handling methods methods defined by the App::Info base
classes (e.g., \f(CW\*(C`error()\*(C'\fR) will work properly.
.IP "\(bu" 4
Use a package-scoped lexical App::Info::Util object to carry out common tasks.
If you find you're doing something over and over that's not already addressed
by an App::Info::Util method, and you think that others might find your
solution useful, consider submitting a patch to App::Info::Util to add the
functionality you need. See App::Info::Util for complete
documentation of its interface.
.IP "\(bu" 4
Use the \f(CW\*(C`info()\*(C'\fR event triggering method to send messages to users of your
subclass.
.IP "\(bu" 4
Use the \f(CW\*(C`error()\*(C'\fR event triggering method to alert users of unexpected
conditions. Fatal errors should still be fatal; use \f(CW\*(C`Carp::croak()\*(C'\fR to throw
exceptions for fatal errors.
.IP "\(bu" 4
Use the \f(CW\*(C`unknown()\*(C'\fR event triggering method when a meta data or other
important value is unknown and you want to give any event handlers the chance
to provide the data.
.IP "\(bu" 4
Use the \f(CW\*(C`confirm()\*(C'\fR event triggering method when a core piece of data is
known (such as the location of an executable in the \f(CW\*(C`new()\*(C'\fR constructor) and
you need to make sure that you have the \fIcorrect\fR information.
.IP "\(bu" 4
Be sure to implement \fBall\fR of the abstract methods defined by App::Info and
by your category abstract base class \*(-- even if they don't do anything. Doing
so ensures that all App::Info subclasses share a common interface, and can, if
necessary, be used without regard to subclass. Any method not implemented but
called on an object will generate a fatal exception.
.PP
Otherwise, have fun! There are a lot of software packages for which relevant
information might be collected and aggregated into an App::Info concrete
subclass (witness all of the Automake macros in the world!), and folks who are
knowledgeable about particular software packages or categories of software are
warmly invited to contribute. As more subclasses are implemented, it will make
sense, I think, to create separate distributions based on category \*(-- or even,
when necessary, on a single software package. Broader categories can then be
aggregated in Bundle distributions.
.PP
But I get ahead of myself...
.SH "SUPPORT"
.IX Header "SUPPORT"
This module is stored in an open GitHub
repository . Feel free to fork and
contribute!
.PP
Please file bug reports via GitHub
Issues or by sending mail to
bug\-App\-Info@rt.cpan.org .
.SH "AUTHOR"
.IX Header "AUTHOR"
David E. Wheeler
.SH "SEE ALSO"
.IX Header "SEE ALSO"
The following classes define a few software package categories in which
App::Info subclasses can be placed. Check them out for ideas on how to
create new category subclasses.
.IP "App::Info::HTTP" 4
.IX Item "App::Info::HTTP"
.PD 0
.IP "App::Info::RDBMS" 4
.IX Item "App::Info::RDBMS"
.IP "App::Info::Lib" 4
.IX Item "App::Info::Lib"
.PD
.PP
The following classes implement the App::Info interface for various software
packages. Check them out for examples of how to implement new App::Info
concrete subclasses.
.IP "App::Info::HTTPD::Apache" 4
.IX Item "App::Info::HTTPD::Apache"
.PD 0
.IP "App::Info::RDBMS::PostgreSQL" 4
.IX Item "App::Info::RDBMS::PostgreSQL"
.IP "App::Info::Lib::Expat" 4
.IX Item "App::Info::Lib::Expat"
.IP "App::Info::Lib::Iconv" 4
.IX Item "App::Info::Lib::Iconv"
.PD
.PP
App::Info::Util provides utility methods for App::Info
subclasses.
.PP
App::Info::Handler defines an interface for event
handlers to subclass. Consult its documentation for information on creating
custom event handlers.
.PP
The following classes implement the App::Info::Handler interface to offer some
simple event handling. Check them out for examples of how to implement new
App::Info::Handler subclasses.
.IP "App::Info::Handler::Print" 4
.IX Item "App::Info::Handler::Print"
.PD 0
.IP "App::Info::Handler::Carp" 4
.IX Item "App::Info::Handler::Carp"
.IP "App::Info::Handler::Prompt" 4
.IX Item "App::Info::Handler::Prompt"
.PD
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
Copyright (c) 2002\-2011, David E. Wheeler. Some Rights Reserved.
.PP
This module is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.