App-Info
view release on metacpan or search on metacpan
lib/App/Info/Request.pm view on Meta::CPAN
See the object methods documentation below for details on these object
attributes.
=cut
sub new {
my $pkg = shift;
# Make sure we've got a hash of arguments.
Carp::croak("Odd number of parameters in call to " . __PACKAGE__ .
"->new() when named parameters expected" ) if @_ % 2;
my %params = @_;
# Validate the callback.
if ($params{callback}) {
Carp::croak("Callback parameter '$params{callback}' is not a code ",
"reference")
unless UNIVERSAL::isa($params{callback}, 'CODE');
} else {
# Otherwise just assign a default approve callback.
$params{callback} = sub { 1 };
}
# Validate type parameter.
if (my $t = $params{type}) {
Carp::croak("Invalid handler type '$t'")
unless $t eq 'error' or $t eq 'info' or $t eq 'unknown'
or $t eq 'confirm';
} else {
$params{type} = 'info';
}
# Return the request object.
bless \%params, ref $pkg || $pkg;
}
##############################################################################
=head2 Object Methods
=head3 key
my $key = $req->key;
Returns the key stored in the App::Info::Request object. The key is used by
the App::Info subclass to uniquely identify the information it is harvesting,
such as the path to an executable. It might be used by request handlers,
for example, to see if an option was passed on the command-line.
=cut
sub key { $_[0]->{key} }
##############################################################################
=head3 message
my $message = $req->message;
Returns the message stored in the App::Info::Request object. The message is
typically informational, or an error message, or a prompt message.
=cut
sub message { $_[0]->{message} }
##############################################################################
=head3 error
my $error = $req->error;
Returns any error message associated with the App::Info::Request object. The
error message is typically there to display for users when C<callback()>
returns false.
=cut
sub error { $_[0]->{error} }
##############################################################################
=head3 type
my $type = $req->type;
Returns a string representing the type of event that triggered this request.
The types are the same as the event triggering methods defined in App::Info.
As of this writing, the supported types are:
=over
=item info
=item error
=item unknown
=item confirm
=back
Be sure to consult the App::Info documentation for more details on the event
types.
=cut
sub type { $_[0]->{type} }
##############################################################################
=head3 callback
if ($req->callback($value)) {
print "Value '$value' is valid.\n";
} else {
print "Value '$value' is not valid.\n";
}
Executes the callback anonymous subroutine supplied by the App::Info concrete
base class that triggered the event. If the callback returns false, then
( run in 0.695 second using v1.01-cache-2.11-cpan-6aa56a78535 )