App-Info

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

      - Improved validation for the error_level parameter.
      - In distribution tests, no longer testing to see that user and group
        methods in HTTP::Apache return values when Apache is installed, as
        sometimes folks don't have User and Group directives set in their
        httpd.conf files. Grrr...
      - Fixed bare word references in Makefile.PL.

0.10  Wed Jun  5 23:58:54 2002
      - Added new error_level parameter to new(). This tells App::Info objects
        how to handle errors on an object-by-object basis. The new base class
        method error() is for subclasses to use for throwing errors, and
        last_error() is for client code to access the last error in non-fatal
        error modes. See App::Info for complete documentation. This is the
        major change the triggered the (mild) version number jump.
      - Reworked all application subclasses to use the new error() method.
      - Changed all application subclasses so that they're no longer singleton
        classes. Each new object construction looks for application metadata
        all over again.
      - Updated documentation on subclassing to reflect changes.
      - Added first_exe() and first_cat_exe() to App::Info::Util. Changed
        RDBMS::PostgreSQL, HTTP::Apache, and Lib::Iconv to use them.

lib/App/Info.pm  view on Meta::CPAN

use strict;
use Carp ();
use App::Info::Handler;
use App::Info::Request;
use vars qw($VERSION);

$VERSION = '0.57';

##############################################################################
##############################################################################
# This code ref is used by the abstract methods to throw an exception when
# they're called directly.
my $croak = sub {
    my ($caller, $meth) = @_;
    $caller = ref $caller || $caller;
    if ($caller eq __PACKAGE__) {
        $meth = __PACKAGE__ . '::' . $meth;
        Carp::croak(__PACKAGE__ . " is an abstract base class. Attempt to " .
                    " call non-existent method $meth");
    } else {
        Carp::croak("Class $caller inherited from the abstract base class " .

lib/App/Info.pm  view on Meta::CPAN

    @{ $self->{on_info} } = $set_handlers->(\@_) if @_;
    return @{ $self->{on_info} };
}

=head3 on_error

  my @handlers = $app->on_error;
  $app->on_error(@handlers);

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 STDERR, once again using the
L<App::Info::Handler::Print|App::Info::Handler::Print> class included with the
App::Info distribution:

  use App::Info::Handler::Print;
  my $app->on_error('stderr');
  # Or:
  my $stderr_handler = App::Info::Handler::Print->new('stderr');
  $app->on_error($stderr_handler);

lib/App/Info.pm  view on Meta::CPAN


      # Return the version number.
      return $ver;
  }

Here we've used the C<info()> method to display a status message to let the
user know what we're doing. Then we used the C<error()> method when something
unexpected happened, which in this case was that we weren't able to find the
version number in the file.

Note the C<_find_file()> 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 C<info()>
method call. But rather than call the C<error()> 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 C<unknown()> method for a case such as this:

  sub _find_file {
      my ($self, $file) = @_;

      # Send a status message.

lib/App/Info.pm  view on Meta::CPAN

documentation of its interface.

=item *

Use the C<info()> event triggering method to send messages to users of your
subclass.

=item *

Use the C<error()> event triggering method to alert users of unexpected
conditions. Fatal errors should still be fatal; use C<Carp::croak()> to throw
exceptions for fatal errors.

=item *

Use the C<unknown()> 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.

=item *

lib/App/Info/Handler.pm  view on Meta::CPAN


  App::Info::Handler->register_handler( $key => $code_ref );

This class method may be used by App::Info::Handler subclasses to register
themselves with App::Info::Handler. Multiple registrations are supported. The
idea is that a subclass can define different functionality by specifying
different strings that represent different modes of constructing an
App::Info::Handler subclass object. The keys are case-sensitive, and should be
unique across App::Info::Handler subclasses so that many subclasses can be
loaded and used separately. If the C<$key> is already registered,
C<register_handler()> will throw an exception. The values are code references
that, when executed, return the appropriate App::Info::Handler subclass
object.

=cut

sub register_handler {
    my ($pkg, $key, $code) = @_;
    Carp::croak("Handler '$key' already exists")
      if $handlers{$key};
    $handlers{$key} = $code;



( run in 0.286 second using v1.01-cache-2.11-cpan-496ff517765 )