Alien-SNMP

 view release on metacpan or  search on metacpan

lib/Alien/SNMP.pm  view on Meta::CPAN

package Alien::SNMP;

use strict;
use warnings;
use 5.010001;
use parent qw(Alien::Base);

our $VERSION = '4.0509050201';

# Preload the dynamic Net-SNMP library with global symbol visibility so that
# the bundled SNMP XS module (which has `use Alien::SNMP;` injected ahead of
# its XSLoader call) and any downstream XS resolve libnetsnmp from our share
# dir whatever path was baked into them: the loader matches the already-loaded
# image by SONAME on ELF, and by install name on darwin.  This is what lets the
# test suite pass before `make install` populates the final share dir (the
# window CPAN Testers run in), and lets the distribution work with no
# system-level libnetsnmp present.
# Best-effort: never let a failure here break `use Alien::SNMP` (e.g. when the
# module is loaded from source before the share dir exists).  The baked-in
# run-path still resolves libnetsnmp once the share is installed.
eval { __PACKAGE__->_preload_netsnmp };

sub _preload_netsnmp {
    my ($class) = @_;
    require DynaLoader;
    DynaLoader::dl_load_file($_, 0x01)   # 0x01 = RTLD_GLOBAL
      for $class->_netsnmp_dynamic_libs;
}

# The dynamic libnetsnmp under whichever name this platform gives it:
# libnetsnmp.so[.N...] on ELF, libnetsnmp[.N...].dylib on darwin.  Sibling
# libraries (libnetsnmpagent and friends) deliberately do not match; libnetsnmp
# is what the bundled XS records as a dependency.  Matching nothing is silent,
# because the preload is best-effort, so t/06 asserts this finds something: an
# ELF-only pattern here is what left macOS unable to run its own test suite.
# The capture also untaints the trusted share-dir path for dl_load_file.
sub _netsnmp_dynamic_libs {
    my ($class) = @_;
    return unless $class->install_type eq 'share';
    return map { m{(/.*/libnetsnmp(?:\.[0-9]+)*\.(?:so(?:\.[0-9]+)*|dylib))\z} ? $1 : () }
           $class->dynamic_libs;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Alien::SNMP - Alien package for the Net-SNMP library

=cut

=head1 SYNOPSIS

 use Alien::SNMP;
 # then it's just like SNMP.pm
 
 say Alien::SNMP->bin_dir;
 # where the net-snmp apps (snmptranslate, etc) live

=head1 DESCRIPTION

L<Alien::SNMP> downloads and installs the Net-SNMP library and
associated perl modules.

The library is built with the following options:

=over

=item C<--disable-agent>

=item C<--disable-manuals>

=item C<--disable-scripts>

=item C<--disable-mibs>

=item C<--enable-ipv6>

=item C<--with-mibs="">

=item C<--with-perl-modules>

=item C<--disable-embedded-perl>

=item C<--enable-blumenthal-aes>

=item C<--with-defaults>

=back



( run in 1.664 second using v1.01-cache-2.11-cpan-744e820c463 )