App-Info

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

use Module::Build;

my $class = Module::Build->subclass(
    class => 'My::Builder',
    code => q{
        sub ACTION_code {
             use File::Spec::Functions;
             my $self = shift;
             $self->SUPER::ACTION_code(@_);
             # Copy the test scripts and then set the shebang line and make
             # sure that they're executable.
             my $from_dir = $self->localize_file_path("t/bin");
             my $to_dir = $self->localize_file_path("t/scripts");

             opendir DIR, $from_dir or die "Cannot open directory '$from_dir': $!\n";
             my @files = grep { !/^\./ } readdir DIR;
             close DIR;

             my @scripts;

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

  }

Finally, the C<confirm()> 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:

  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('/bin/myapp', '/usr/bin/myapp')) {
          # Confirm it.
          $self->{exe} =
            $self->confirm( key      => 'binary',
                            prompt   => 'Path to your executable?',
                            value    => $exe,
                            callback => sub { -x },

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

C<confirm()> method is quite similar to that of C<unknown()>. 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
F</bin/myapp>, but the user may really be interested in F</usr/bin/myapp>.
Thus the C<confirm()> event gives the user the chance to change the value if
the confirm event is handled.

The final thing to note about this constructor is the first line:

  my $self = shift->SUPER::new(@_);

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
C<confirm()> or C<unknown()> the event will be handled as the client expects.

If we needed our subclass constructor to take its own parameter argument, the
approach is to specify the same C<key => $arg> syntax as is used by
App::Info's C<new()> 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.

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


This approach allows the super class constructor arguments to pass unmolested
(as long as we use unique keys!):

  my $app = App::Info::Category::FooApp->new( on_error  => \@handlers,
                                              alt_paths => \@paths );

Then, to retrieve these paths inside our C<new()> constructor, all we need do
is access them directly from the object:

  my $self = shift->SUPER::new(@_);
  my $alt_paths = $self->{alt_paths};

=head2 Subclassing Guidelines

To summarize, here are some guidelines for subclassing App::Info.

=over 4

=item *

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.

=item *

When you create the C<new()> constructor, always call C<SUPER::new(@_)>. This
ensures that the event handling methods methods defined by the App::Info base
classes (e.g., C<error()>) will work properly.

=item *

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 L<App::Info::Util|App::Info::Util> for complete

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

=item unknown

Path to your httpd executable?

=back

=cut

sub new {
    # Construct the object.
    my $self = shift->SUPER::new(@_);

    for my $exe (qw(search_conf_dirs search_conf_names),
                 map { "search_$_\_names" } @EXES
    ) {
        if (exists $self->{$exe}) {
            $self->{$exe} = [$self->{$exe}] unless ref $self->{$exe} eq 'ARRAY';
        } else {
            $self->{$exe} = [];
        }
    }

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

=item apache2

=back

=cut

sub search_exe_names {
    my $self = shift;
    my @exes = qw(httpd httpd2 apache-perl apache apache2);
    if (WIN32) { $_ .= ".exe" for @exes }
    return ( $self->SUPER::search_exe_names, @exes );
}

##############################################################################

=head3 search_bin_dirs

  my @search_bin_dirs = $apache->search_bin_dirs;

Returns a list of possible directories in which to search an executable. Used
by the C<new()> constructor to find an executable to execute and collect

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


=back

=cut

sub search_bin_dirs {
    # See if mod_perl2 knows where Apache is installed.
    eval { require Apache2::BuildConfig };
    my @path = $@ ? () : Apache2::BuildConfig->new->{APXS_BINDIR};
    return (
        shift->SUPER::search_bin_dirs,
        $u->path,
        @path,
        qw(
           /usr/local/apache/bin
           /usr/local/apache2/bin
           /opt/apache/bin
           /opt/apache2/bin
           /usr/local/bin
           /usr/local/sbin
           /usr/bin

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

=item libexec

=back

=cut

sub search_lib_dirs {
    my $self = shift;
    my $root = $self->httpd_root;
    return (
        $self->SUPER::search_lib_dirs,
        ( $root
          ? map { $u->catdir($root, $_) } qw(lib libexec modules)
          : ()
        ),
        '/usr/lib/apache/1.3',
        '/usr/lib/apache/2.0',
    );
}

##############################################################################

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

=item inc

=back

=cut

sub search_inc_dirs {
    my $self = shift;
    my $root = $self->httpd_root;
    return (
      $self->SUPER::search_inc_dirs,
      ( $root
        ? map { $u->catdir($root, $_) } qw(include inc)
        : ()
      ),
    );
}

##############################################################################

=head3 search_conf_names

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

=head2 The Interface

To create an App::Info event handler, all one need do is subclass
App::Info::Handler and then implement the C<new()> constructor and the
C<handler()> method. The C<new()> constructor can do anything you like, and
take any arguments you like. However, I do recommend that the first thing
you do in your implementation is to call the super constructor:

  sub new {
      my $pkg = shift;
      my $self = $pkg->SUPER::new(@_);
      # ... other stuff.
      return $self;
  }

Although the default C<new()> constructor currently doesn't do much, that may
change in the future, so this call will keep you covered. What it does do is
take the parameterized arguments and assign them to the App::Info::Handler
object. Thus if you've specified a "mode" argument, where clients can
construct objects of you class like this:

  my $handler = FooHandler->new( mode => 'foo' );

You can access the mode parameter directly from the object, like so:

  sub new {
      my $pkg = shift;
      my $self = $pkg->SUPER::new(@_);
      if ($self->{mode} eq 'foo') {
          # ...
      }
      return $self;
  }

Just be sure not to use a parameter key name required by App::Info::Handler
itself. At the moment, the only parameter accepted by App::Info::Handler is
"key", so in general you'll be pretty safe.

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

=back

If the C<level> parameter is not passed, C<new()> will default to creating an
App::Info::Handler::Carp object that passes App::Info event messages to
C<Carp::carp()>.

=cut

sub new {
    my $pkg = shift;
    my $self = $pkg->SUPER::new(@_);
    if ($self->{level}) {
        Carp::croak("Invalid error handler '$self->{level}'")
          unless $levels{$self->{level}};
    } else {
        $self->{level} = 'carp';
    }
    return $self;
}

sub handler {

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

=back

If the C<fh> parameter is not passed, C<new()> will default to creating an
App::Info::Handler::Print object that prints App::Info event messages to
C<STDOUT>.

=cut

sub new {
    my $pkg = shift;
    my $self = $pkg->SUPER::new(@_);
    if (!defined $self->{fh} || $self->{fh} eq 'stderr') {
        # Create a reference to STDERR.
        $self->{fh} = \*STDERR;
    } elsif ($self->{fh} eq 'stdout') {
        # Create a reference to STDOUT.
        $self->{fh} = \*STDOUT;
    } elsif (!ref $self->{fh}) {
        # Assume a reference to a filehandle or else it's invalid.
        Carp::croak("Invalid argument to new(): '$self->{fh}'");
    }

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


  my $prompter = App::Info::Handler::Prompt->new;

Constructs a new App::Info::Handler::Prompt object and returns it. No special
arguments are required.

=cut

sub new {
    my $pkg = shift;
    my $self = $pkg->SUPER::new(@_);
    $self->{tty} = -t STDIN && ( -t STDOUT || !( -f STDOUT || -c STDOUT ) );
    # We're done!
    return $self;
}

my $get_ans = sub {
    my ($prompt, $tty, $def) = @_;
    # Print the message.
    local $| = 1;
    local $\;

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

=item unknown

Path to Expat library directory?

=back

=cut

sub new {
    # Construct the object.
    my $self = shift->SUPER::new(@_);
    # Find libexpat.
    $self->info("Searching for Expat libraries");

    my @libs = $self->search_lib_names;
    my $cb = sub { $u->first_cat_dir(\@libs, $_) };
    if (my $lexpat = $u->first_cat_dir(\@libs, $self->search_lib_dirs)) {
        # We found libexpat. Confirm.
        $self->{libexpat} =
          $self->confirm( key      => 'expat lib dir',
                          prompt   => 'Path to Expat library directory?',

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

=item libexpat.0.dylib

=item libexpat.0.0.1.dylib

=back

=cut

sub search_lib_names {
    my $self = shift;
    return $self->SUPER::search_lib_names,
      map { "libexpat.$_"} qw(a la so so.0 so.0.0.1 dylib 0.dylib 0.0.1.dylib);
}

##############################################################################

=head3 search_so_lib_names

  my @seach_so_lib_names = $self->search_so_lib_nams

Returns a list of possible names for shared object library files. Used by

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

=item libexpat.0.dylib

=item libexpat.0.0.1.dylib

=back

=cut

sub search_so_lib_names {
    my $self = shift;
    return $self->SUPER::search_so_lib_names,
      map { "libexpat.$_"} qw(so so.0 so.0.0.1 dylib 0.dylib 0.0.1.dylib);
}

##############################################################################

=head3 search_lib_dirs

  my @search_lib_dirs = $expat->search_lib_dirs;

Returns a list of possible directories in which to search for libraries. By
default, it returns all of the paths in the C<libsdirs> and C<loclibpth>
attributes defined by the Perl L<Config|Config> module -- plus F</sw/lib> (in
support of all you Fink users out there).

=cut

sub search_lib_dirs { shift->SUPER::search_lib_dirs, $u->lib_dirs, '/sw/lib' }

##############################################################################

=head3 search_inc_names

  my @search_inc_names = $expat->search_inc_names;

Returns a list of include file names to search for. Used by C<inc_dir()> to
search for an include file. By default, the only name returned is F<expat.h>.

=cut

sub search_inc_names {
    my $self = shift;
    return $self->SUPER::search_inc_names, "expat.h";
}

##############################################################################

=head3 search_inc_dirs

  my @search_inc_dirs = $expat->search_inc_dirs;

Returns a list of possible directories in which to search for include files.
Used by C<inc_dir()> to search for an include file. By default, the

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


=item /usr/include

=item /sw/include

=back

=cut

sub search_inc_dirs {
    shift->SUPER::search_inc_dirs,
      qw(/usr/local/include
         /usr/include
         /sw/include);
}

1;
__END__

=head1 KNOWN ISSUES

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


=item confirm

Path to iconv executable?

=back

=cut

sub new {
    my $self = shift->SUPER::new(@_);
    # Find iconv.
    $self->info("Searching for iconv");

    if (my $exe = $u->first_cat_exe([$self->search_exe_names],
                                    $self->search_bin_dirs)) {
        # We found it. Confirm.
        $self->{executable} = $self->confirm(
            key      => 'path to iconv',
            prompt   => 'Path to iconv executable?',
            value    => $exe,

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


Returns a list of possible names for the Iconv executable. By default, the
only name returned is F<iconv> (F<iconv.exe> on Win32).

=cut

sub search_exe_names {
    my $self = shift;
    my @exes = qw(iconv);
    if (WIN32) { $_ .= ".exe" for @exes }
    return ($self->SUPER::search_exe_names, @exes);
}

##############################################################################

=head3 search_bin_dirs

  my @search_bin_dirs = $iconv->search_bin_dirs;

Returns a list of possible directories in which to search an executable. Used
by the C<new()> constructor to find an executable to execute and collect

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

=item F</sbin>

=item F</sw/sbin>

=back

=cut

sub search_bin_dirs {
    return (
      shift->SUPER::search_bin_dirs,
      $u->path,
      qw(/usr/local/bin
         /usr/bin
         /bin
         /sw/bin
         /usr/local/sbin
         /usr/sbin/
         /sbin
         /sw/sbin)
    );

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

=item libiconv.0.dylib

=item libiconv.0.0.1.dylib

=back

=cut

sub search_lib_names {
    my $self = shift;
    return $self->SUPER::search_lib_names,
      map { "libiconv.$_"} qw(a la so so.0 so.0.0.1 dylib 2.dylib 2.0.4.dylib
                              0.dylib 0.0.1.dylib);
}

##############################################################################

=head3 search_so_lib_names

  my @seach_so_lib_names = $self->search_so_lib_nams

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

=item libiconv.0.dylib

=item libiconv.0.0.1.dylib

=back

=cut

sub search_so_lib_names {
    my $self = shift;
    return $self->SUPER::search_so_lib_names,
      map { "libiconv.$_"} qw(so so.0 so.0.0.1 dylib 2.dylib 2.0.4.dylib
                              0.dylib 0.0.1.dylib);
}

##############################################################################

=head3 search_lib_dirs

  my @search_lib_dirs = $iconv->search_lib_dirs;

Returns a list of possible directories in which to search for libraries. By
default, it returns all of the paths in the C<libsdirs> and C<loclibpth>
attributes defined by the Perl L<Config|Config> module -- plus F</sw/lib> (in
support of all you Fink users out there).

=cut

sub search_lib_dirs { shift->SUPER::search_lib_dirs, $u->lib_dirs, '/sw/lib' }

##############################################################################

=head3 search_inc_names

  my @search_inc_names = $iconv->search_inc_names;

Returns a list of include file names to search for. Used by C<inc_dir()> to
search for an include file. By default, the only name returned is F<iconv.h>.

=cut

sub search_inc_names {
    my $self = shift;
    return $self->SUPER::search_inc_names, "iconv.h";
}

##############################################################################

=head3 search_inc_dirs

  my @search_inc_dirs = $iconv->search_inc_dirs;

Returns a list of possible directories in which to search for include files.
Used by C<inc_dir()> to search for an include file. By default, the

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


=item /usr/include

=item /sw/include

=back

=cut

sub search_inc_dirs {
    shift->SUPER::search_inc_dirs,
      qw(/usr/local/include
         /usr/include
         /sw/include);
}

1;
__END__

=head1 KNOWN ISSUES

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

=item unknown

Path to uuid-config?

=back

=cut

sub new {
    # Construct the object.
    my $self = shift->SUPER::new(@_);

    # Find uuid-config.
    $self->info("Looking for uuid-config");

    my @paths = $self->search_bin_dirs;
    my @exes  = $self->search_exe_names;

    if (my $cfg = $u->first_cat_exe(\@exes, @paths)) {
        # We found it. Confirm.
        $self->{uuid_config} = $self->confirm(

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


Note that this method is not used to search for the OSSP UUID server
executable, only F<uuid-config>.

=cut

sub search_exe_names {
    my $self = shift;
    my $exe = 'uuid-config';
    $exe .= '.exe' if WIN32;
    return ($self->SUPER::search_exe_names, $exe);
}

##############################################################################

=head3 search_bin_dirs

  my @search_bin_dirs = $app->search_bin_dirs;

Returns a list of possible directories in which to search an executable. Used
by the C<new()> constructor to find an executable to execute and collect

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


=item /bin

=item C:\Program Files\uid\bin

=back

=cut

sub search_bin_dirs {
    return shift->SUPER::search_bin_dirs,
      $u->path,
      qw(/usr/local/bin
         /usr/local/sbin
         /usr/bin
         /usr/sbin
         /bin),
      'C:\Program Files\uid\bin';
}

##############################################################################

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

=item unknown

Path to pg_config?

=back

=cut

sub new {
    # Construct the object.
    my $self = shift->SUPER::new(@_);

    # Find pg_config.
    $self->info("Looking for pg_config");

    my @paths = $self->search_bin_dirs;
    my @exes = $self->search_exe_names;

    if (my $cfg = $u->first_cat_exe(\@exes, @paths)) {
        # We found it. Confirm.
        $self->{pg_config} = $self->confirm( key      => 'path to pg_config',

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


Note that this method is not used to search for the PostgreSQL server
executable, only F<pg_config>.

=cut

sub search_exe_names {
    my $self = shift;
    my $exe = 'pg_config';
    $exe .= '.exe' if WIN32;
    return ($self->SUPER::search_exe_names, $exe);
}

##############################################################################

=head3 search_bin_dirs

  my @search_bin_dirs = $app->search_bin_dirs;

Returns a list of possible directories in which to search an executable. Used
by the C<new()> constructor to find an executable to execute and collect

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


=item /bin

=item C:\Program Files\PostgreSQL\bin

=back

=cut

sub search_bin_dirs {
    return shift->SUPER::search_bin_dirs,
      ( exists $ENV{POSTGRES_HOME}
          ? ($u->catdir($ENV{POSTGRES_HOME}, "bin"))
          : ()
      ),
      ( exists $ENV{POSTGRES_LIB}
          ? ($u->catdir($ENV{POSTGRES_LIB}, $u->updir, "bin"))
          : ()
      ),
      $u->path,
      qw(/usr/local/pgsql/bin

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

=item unknown

Path to SQLite executable?

=back

=cut

sub new {
    # Construct the object.
    my $self = shift->SUPER::new(@_);

    # Find pg_config.
    $self->info("Looking for SQLite");

    my @exes = $self->search_exe_names;
    if (my $cfg = $u->first_cat_exe(\@exes, $self->search_bin_dirs)) {
        # We found it. Confirm.
        $self->{executable} = $self->confirm(
            key      => 'path to sqlite',
            prompt   => "Path to SQLite executable?",

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

Returns a list of possible names for the SQLite executable. The names are
F<sqlite3> and F<sqlite> by default (F<sqlite3.exe> and F<sqlite.exe> on
Win32).

=cut

sub search_exe_names {
    my $self = shift;
    my @exes = qw(sqlite3 sqlite);
    if (WIN32) { $_ .= ".exe" for @exes }
    return ($self->SUPER::search_exe_names, @exes);
}

##############################################################################

=head3 search_bin_dirs

  my @search_bin_dirs = $sqlite->search_bin_dirs;

Returns a list of possible directories in which to search an executable. Used
by the C<new()> constructor to find an executable to execute and collect
application info. The found directory will also be returned by the C<bin_dir>
method.

=cut

sub search_bin_dirs { (shift->SUPER::search_bin_dirs, $u->path) }

##############################################################################

=head3 search_lib_names

  my @seach_lib_names = $self->search_lib_nams

Returns a list of possible names for library files. Used by C<lib_dir()> to
search for library files. By default, the list is:

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


=item libsqlite.0.0.1.dylib

=back

=cut

sub search_lib_names {
    my $self = shift;
    (my $exe = $u->splitpath($self->{executable})) =~ s/\.[^.]+$//;
    return $self->SUPER::search_lib_names,
      map { "lib$exe.$_"} qw(a la so so.0 so.0.0.1 dylib 0.dylib 0.0.1.dylib);
}

##############################################################################

=head3 search_so_lib_names

  my @seach_so_lib_names = $self->search_so_lib_nams

Returns a list of possible names for shared object library files. Used by

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


=item libsqlite.0.0.1.dylib

=back

=cut

sub search_so_lib_names {
    my $self = shift;
    (my $exe = $u->splitpath($self->{executable})) =~ s/\.[^.]+$//;
    return $self->SUPER::search_so_lib_names,
      map { "lib$exe.$_"}
        qw(so so.0 so.0.0.1 dylib 0.dylib 0.0.1.dylib);
}

##############################################################################

=head3 search_lib_dirs

  my @search_lib_dirs = $sqlite->search_lib_dirs;

Returns a list of possible directories in which to search for libraries. By
default, it returns all of the paths in the C<libsdirs> and C<loclibpth>
attributes defined by the Perl L<Config|Config> module -- plus F</sw/lib> (in
support of all you Fink users out there).

=cut

sub search_lib_dirs { shift->SUPER::search_lib_dirs, $u->lib_dirs, '/sw/lib' }

##############################################################################

=head3 search_inc_names

  my @search_inc_names = $sqlite->search_inc_names;

Returns a list of include file names to search for. Used by C<inc_dir()> to
search for an include file. By default, the names are F<sqlite3.h> and
F<sqlite.h>.

=cut

sub search_inc_names {
    my $self = shift;
    (my $exe = $u->splitpath($self->{executable})) =~ s/\.[^.]+$//;
    return $self->SUPER::search_inc_names, "$exe.h";
}

##############################################################################

=head3 search_inc_dirs

  my @search_inc_dirs = $sqlite->search_inc_dirs;

Returns a list of possible directories in which to search for include files.
Used by C<inc_dir()> to search for an include file. By default, the

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


=item /usr/include

=item /sw/include

=back

=cut

sub search_inc_dirs {
    shift->SUPER::search_inc_dirs,
      qw(/usr/local/include
         /usr/include
         /sw/include);
}

1;
__END__

=head1 SUPPORT

t/lib/EventTest.pm  view on Meta::CPAN

package EventTest;

use strict;
use App::Info::Handler;
use vars qw(@ISA);
@ISA = 'App::Info::Handler';

sub new {
    my $pkg = shift;
    my $self = $pkg->SUPER::new(@_);
    $self->{req} = [];
    return $self;
}

sub request {
    return shift @{$_[0]->{req}};
}

sub requests {
    my @reqs = @{$_[0]->{req}};



( run in 1.854 second using v1.01-cache-2.11-cpan-49f99fa48dc )