App-Info
view release on metacpan or search on metacpan
lib/App/Info/Lib/Iconv.pm view on Meta::CPAN
Some of the methods trigger the same events. This is due to cross-calling of
shared subroutines. However, any one event should be triggered no more than
once. For example, although the info event "Searching for 'iconv.h'" is
documented for the methods C<version()>, C<major_version()>, and
C<minor_version()>, rest assured that it will only be triggered once, by
whichever of those four methods is called first.
=cut
use strict;
use File::Basename ();
use App::Info::Util;
use App::Info::Lib;
use vars qw(@ISA $VERSION);
@ISA = qw(App::Info::Lib);
$VERSION = '0.57';
use constant WIN32 => $^O eq 'MSWin32';
my $u = App::Info::Util->new;
##############################################################################
=head1 INTERFACE
=head2 Constructor
=head3 new
my $iconv = App::Info::Lib::Iconv->new(@params);
Returns an App::Info::Lib::Iconv object. See L<App::Info|App::Info> for a
complete description of argument parameters.
When called, C<new()> searches the the list of directories returned by the
C<search_bin_dirs()> method for an executable file with a name returned by the
C<search_exe_names()> method. If the executable is found, libiconv will be
assumed to be installed. Otherwise, most of the object methods will return
C<undef>.
B<Events:>
=over 4
=item info
Searching for iconv
=item unknown
Path to iconv executable?
=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,
callback => sub { -x },
error => 'Not an executable'
);
} else {
# No luck. Ask 'em for it.
$self->{executable} = $self->unknown(
key => 'path to iconv',
prompt => 'Path to iconv executable?',
callback => sub { -x },
error => 'Not an executable'
);
}
return $self;
}
##############################################################################
=head2 Class Method
=head3 key_name
my $key_name = App::Info::Lib::Iconv->key_name;
Returns the unique key name that describes this class. The value returned is
the string "libiconv".
=cut
sub key_name { 'libiconv' }
##############################################################################
=head2 Object Methods
=head3 installed
print "libiconv is ", ($iconv->installed ? '' : 'not '),
"installed.\n";
Returns true if libiconv is installed, and false if it is not.
App::Info::Lib::Iconv determines whether libiconv is installed based on the
presence or absence of the F<iconv> application, as found when C<new()>
constructed the object. If libiconv does not appear to be installed, then most
of the other object methods will return empty values.
=cut
sub installed { $_[0]->{executable} ? 1 : undef }
lib/App/Info/Lib/Iconv.pm view on Meta::CPAN
my $self = shift;
return unless $self->{executable};
unless (exists $self->{so_lib_dir}) {
$self->info("Searching for shared object library directory");
my @files = $self->search_so_lib_names;
if (my $dir = $u->first_cat_dir(\@files, $self->search_lib_dirs)) {
$self->{so_lib_dir} = $dir;
} else {
$self->error("Cannot find shared object library directory");
my $cb = sub { $u->first_cat_dir(\@files, $_) };
$self->{so_lib_dir} =
$self->unknown( key => 'iconv so dir',
callback => $cb,
error => "Shared object libraries not " .
"found in directory");
}
}
return $self->{so_lib_dir};
}
##############################################################################
=head3 home_url
my $home_url = $iconv->home_url;
Returns the libiconv home page URL.
=cut
sub home_url { 'http://www.gnu.org/software/libiconv/' }
##############################################################################
=head3 download_url
my $download_url = $iconv->download_url;
Returns the libiconv download URL.
=cut
sub download_url { 'ftp://ftp.gnu.org/pub/gnu/libiconv/' }
##############################################################################
=head3 search_exe_names
my @search_exe_names = $iconv->search_exe_names;
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
application info. The found directory will also be returned by the C<bin_dir>
method. By default, the directories returned are those in your path, followed
by these:
=over 4
=item F</usr/local/bin>
=item F</usr/bin>
=item F</bin>
=item F</sw/bin>
=item F</usr/local/sbin>
=item F</usr/sbin>
=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)
);
}
##############################################################################
=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:
=over
=item libiconv3.a
=item libiconv3.la
=item libiconv3.so
=item libiconv3.so.0
=item libiconv3.so.0.0.1
=item libiconv3.dylib
=item libiconv3.0.dylib
=item libiconv3.0.0.1.dylib
=item libiconv.a
=item libiconv.la
=item libiconv.so
=item libiconv.so.0
=item libiconv.so.0.0.1
=item libiconv.dylib
=item libiconv.2.dylib
=item libiconv.2.0.4.dylib
=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
Returns a list of possible names for shared object library files. Used by
C<so_lib_dir()> to search for library files. By default, the list is:
=over
=item libiconv3.so
=item libiconv3.so.0
=item libiconv3.so.0.0.1
=item libiconv3.dylib
=item libiconv3.0.dylib
=item libiconv3.0.0.1.dylib
=item libiconv.so
=item libiconv.so.0
=item libiconv.so.0.0.1
=item libiconv.dylib
=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
directories are:
=over 4
=item /usr/local/include
=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
This is a pretty simple class. It's possible that there are more directories
that ought to be searched for libraries and includes.
=head1 TO DO
Improve this class by borrowing code from Matt Seargent's AxKit F<Makefil.PL>.
=head1 SUPPORT
This module is stored in an open L<GitHub
repository|http://github.com/theory/app-info/>. Feel free to fork and
contribute!
Please file bug reports via L<GitHub
Issues|http://github.com/theory/app-info/issues/> or by sending mail to
L<bug-App-Info@rt.cpan.org|mailto:bug-App-Info@rt.cpan.org>.
=head1 AUTHOR
David E. Wheeler <david@justatheory.com> based on code by Sam Tregar
<sam@tregar.com>.
=head1 SEE ALSO
L<App::Info|App::Info>,
L<App::Info::Lib|App::Info::Lib>,
L<Text::Iconv|Text::Iconv>
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2002-2011, David E. Wheeler. Some Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the
same terms as Perl itself.
=cut
( run in 1.945 second using v1.01-cache-2.11-cpan-a5162978ef8 )