### Synopsis example: Listing modules Source: https://perldoc.perl.org/5.42.0/-RC1/ExtUtils%3A%3AInstalled Demonstrates how to use the ExtUtils::Installed module to get a list of all installed Perl modules. ```perl use ExtUtils::Installed; my ($inst) = ExtUtils::Installed->new( skip_cwd => 1 ); my (@modules) = $inst->modules(); ``` -------------------------------- ### Module::Build Installation Steps Source: https://perldoc.perl.org/5.42.0/-RC1/perlmodstyle Standard installation commands when using Module::Build for Perl modules. This covers building the module, running tests, and installing it. ```perl perl Build.PL perl Build perl Build test perl Build install ``` -------------------------------- ### Perl: Installing Modules from CPAN Source: https://perldoc.perl.org/5.42.0/perlfaq8 Provides examples of installing Perl modules from CPAN using the `cpan` and `cpanp` commands. It also shows how to install a distribution from the current directory and manual installation steps for distributions using Makefile.PL or Build.PL. ```bash $ cpan IO::Interactive Getopt::Whatever ``` ```bash $ cpanp i IO::Interactive Getopt::Whatever ``` ```bash $ cpan . ``` ```bash $ perl Makefile.PL $ make test install ``` ```bash $ perl Build.PL $ ./Build test $ ./Build install ``` -------------------------------- ### Build and Install Perl Module (Unix) Source: https://perldoc.perl.org/5.42.0/perlmodinstall Steps to build and install a Perl module on Unix-like systems. This involves running Makefile.PL, testing the module with 'make test', and installing it with 'make install'. ```bash perl Makefile.PL make test make install ``` -------------------------------- ### Synopsis example: Getting module packlist Source: https://perldoc.perl.org/5.42.0/-RC1/ExtUtils%3A%3AInstalled Demonstrates how to access the packlist information for a specific installed module ('DBI'). ```perl use ExtUtils::Installed; my ($inst) = ExtUtils::Installed->new( skip_cwd => 1 ); my $packlist = $inst->packlist("DBI"); ``` -------------------------------- ### App::Cpan: Basic Usage and Installation Source: https://perldoc.perl.org/5.42.0/-RC2/App%3A%3ACpan Demonstrates common command-line invocations for installing modules, starting the CPAN shell, and performing basic operations without specific switches. It highlights how to install one or more modules by name. ```bash cpan module_name [ module_name ... ] cpan . cpan cpan [-ahpruvACDLOPX] ``` -------------------------------- ### Installing CPAN Modules Source: https://perldoc.perl.org/5.42.0/-RC2/perlfaq8 Provides command-line examples for installing Perl modules from CPAN using the 'cpan' and 'cpanp' commands. It also shows how to install a module from the current directory. ```bash $ cpan IO::Interactive Getopt::Whatever $ cpanp i IO::Interactive Getopt::Whatever $ cpan . ``` -------------------------------- ### Perl CPAN Client Examples Source: https://perldoc.perl.org/5.42.0/-RC1/cpan Various command-line examples demonstrating how to use the 'cpan' script to interact with CPAN. These examples cover common tasks such as displaying help, checking versions, creating autobundles, recompiling modules, upgrading installed modules, and installing specific modules. ```shell cpan -h ``` ```shell cpan -v ``` ```shell cpan -a ``` ```shell cpan -r ``` ```shell cpan -u ``` ```shell cpan -i Netscape::Booksmarks Business::ISBN ``` -------------------------------- ### Perl Build and Install (Unix/Windows) Source: https://perldoc.perl.org/5.42.0/perlmodinstall Standard procedure for building and installing Perl modules on Unix-like systems and Windows using `nmake` or `perl Makefile.PL`. ```shell perl Makefile.PL nmake test nmake install ``` ```shell perl Makefile.PL nmake test ``` -------------------------------- ### Perl Installation Source: https://perldoc.perl.org/5.42.0/-RC1/perlko This snippet shows the standard commands to configure, compile, test, and install Perl from source. It assumes a Unix-like environment and sets the installation prefix to `$HOME/localperl`. ```bash ./Configure -des -Dprefix=$HOME/localperl make test make install ``` -------------------------------- ### Programmatic Update Check Example Source: https://perldoc.perl.org/5.42.0/-RC1/CPAN A practical example of combining CPAN functionalities programmatically, specifically to install all outdated modules on a local disk. This requires prior setup of CPAN components. ```perl # install everything that is outdated on my disk: ``` -------------------------------- ### init_INST Source: https://perldoc.perl.org/5.42.0/ExtUtils%3A%3AMM_Any Sets up installation paths for various components like libraries, binaries, and man directories. ```APIDOC ## init_INST ### Description Sets up all `INST_*` variables, except those related to XS code. These variables define the installation paths for the module's components. ### Method sub init_INST ### Endpoint N/A (Internal MakeMaker method) ### Parameters None ### Request Example ```perl $mm->init_INST; ``` ### Response Sets internal `INST_*` variables. #### Success Response (200) * `$self->{INST_ARCHLIB}` (string) - Installation path for architecture-dependent libraries. * `$self->{INST_BIN}` (string) - Installation path for binaries. * `$self->{INST_LIB}` (string) - Installation path for pure Perl libraries. * `$self->{INST_LIBDIR}` (string) - Installation path for module's library directory. * `$self->{INST_ARCHLIBDIR}` (string) - Installation path for module's architecture-dependent library directory. * `$self->{INST_AUTODIR}` (string) - Installation path for auto-generated pure Perl files. * `$self->{INST_ARCHAUTODIR}` (string) - Installation path for auto-generated architecture-dependent files. * `$self->{INST_SCRIPT}` (string) - Installation path for scripts. * `$self->{INST_MAN1DIR}` (string) - Installation path for man pages (section 1). * `$self->{INST_MAN3DIR}` (string) - Installation path for man pages (section 3). ### Note Handles `PERL_CORE` setting for `INST_LIB` and `INST_ARCHLIB`. ``` -------------------------------- ### init_INSTALL Source: https://perldoc.perl.org/5.42.0/-RC3/ExtUtils%3A%3AMM_Any Initializes installation-related variables (INSTALL_* and *PREFIX). Sets up variables related to the installation base and prefix. ```APIDOC ## init_INSTALL ### Description Initializes all INSTALL_* variables (except INSTALLDIRS) and *PREFIX variables. Sets up variables related to the installation base and prefix. ### Method (Internal MakeMaker initialization) ### Endpoint N/A (Internal MakeMaker function) ### Parameters None ### Request Example ```perl $mm->init_INSTALL; ``` ### Response None (Modifies internal MakeMaker state) ``` -------------------------------- ### init_INST Source: https://perldoc.perl.org/5.42.0/-RC3/ExtUtils%3A%3AMM_Any Initializes installation-related variables (INST_*). Sets default paths for libraries, binaries, and man directories. ```APIDOC ## init_INST ### Description Initializes all INST_* variables except those related to XS code. Sets default installation paths for architecture-dependent libraries, binaries, and man directories. ### Method (Internal MakeMaker initialization) ### Endpoint N/A (Internal MakeMaker function) ### Parameters None ### Request Example ```perl $mm->init_INST; ``` ### Response Returns 1 upon successful initialization (Modifies internal MakeMaker state) ``` -------------------------------- ### Initialize Installation Paths from INSTALL_BASE Source: https://perldoc.perl.org/5.42.0/-RC3/ExtUtils%3A%3AMM_Any Initializes installation paths based on the $(INSTALL_BASE) macro. It maps generic directory names to specific path components and sets up variables like PREFIX, VENDORPREFIX, SITEPREFIX, and PERLPREFIX. It handles the creation of installation paths for libraries, architecture-specific libraries, binaries, and man pages. ```perl my %map = ( lib => [qw(lib perl5)], arch => [('lib', 'perl5', $Config{archname})], bin => [qw(bin)], man1dir => [qw(man man1)], man3dir => [qw(man man3)] ); $map{script} = $map{bin}; sub init_INSTALL_from_INSTALL_BASE { my $self = shift; @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} = '$(INSTALL_BASE)'; my %install; foreach my $thing (keys %map) { foreach my $dir (('', 'SITE', 'VENDOR')) { my $uc_thing = uc $thing; my $key = "INSTALL".$dir.$uc_thing; $install{$key} ||= ($thing =~ /^man.dir$/ and not $Config{lc $key}) ? 'none' : $self->catdir('$(INSTALL_BASE)', @{$map{$thing}}); } } # Adjust for variable quirks. $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH}; $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB}; foreach my $key (keys %install) { $self->{$key} ||= $install{$key}; } return 1; } ``` -------------------------------- ### Test2 Overview Source: https://perldoc.perl.org/5.42.0/-RC1/Test2 Provides an overview of the Test2 framework, its key features, and namespace layout. It also guides users on getting started with writing tests or tools. ```APIDOC ## Test2 Framework Overview ### Description Test2 is a Perl testing framework designed to replace and improve upon Test::Builder. It offers enhanced features for writing test tools, diagnostics, and supporting various output formats. ### Key Features: * **Easier to test new testing tools**: Built with introspection capabilities, making it simple to capture and verify test tool output. * **Better diagnostics capabilities**: Utilizes `Test2::API::Context` for improved tracking of filenames, line numbers, and tool details. * **Event driven**: Employs an event system for rich plugin and extension support. * **More complete API**: Provides public API functions for a wider range of functionalities compared to Test::Builder. * **Support for output other than TAP**: Allows specification of alternative and custom formatters. * **Sane subtest implementation**: Uses a stacked event hub system for improved subtest management. * **Support for threading/forking**: Integrates with `Test2::IPC` for sane threading and forking support. ### Getting Started: * **Writing Tests**: Use `Test2::Suite` for tools and utilities. * **Writing Tools**: Start with `Test2::API`. ### Namespace Layout: * **`Test2::Tools::`**: For sets of tools (e.g., `ok()`, `is()`). * **`Test2::Plugin::`**: For modules that modify or enhance Test2 behavior. * **`Test2::Bundle::`**: For collections of tools and plugins. * **`Test2::Require::`**: For modules that conditionally skip tests. * **`Test2::Formatter::`**: For output formatters (e.g., `Test2::Formatter::TAP`). * **`Test2::Event::`**: For defining event types. * **`Test2::Hub::`**: For hub subclasses and utility objects. * **`Test2::IPC::`**: For the Inter-Process Communication subsystem. * **`Test2::IPC::Driver::`**: For IPC driver implementations. * **`Test2::Util::`**: For general utilities used by testing tools. * **`Test2::API::`**: For the Test2 API and related packages. * **`Test2::`**: For extensions and frameworks used to build tools and plugins. ``` -------------------------------- ### Perl Formatting Example: Top-of-Form Processing Source: https://perldoc.perl.org/5.42.0/perlform Illustrates how to define top-of-form processing in Perl using `format STDOUT_TOP`. This is typically used for headers and page setup, triggered at the start of each page. It shows examples for a passwd file report and a bug report form. ```perl # a report on the /etc/passwd file format STDOUT_TOP = Passwd File Name Login Office Uid Gid Home ------------------------------------------------------------------ . format STDOUT = @<<<<<<<<<<<<<<<<<< @||||||| @<<<<<<@>>>> @>>>> @<<<<<<<<<<<<<<<<< $name, $login, $office,$uid,$gid, $home . ``` ```perl # a report from a bug report form format STDOUT_TOP = Bug Reports @<<<<<<<<<<<<<<<<<<<<<<< @||| @>>>>>>>>>>>>>>>>>>>>>>> $system, $%, $date ------------------------------------------------------------------ . format STDOUT = Subject: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $subject Index: @<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $index, $description Priority: @<<<<<<<<<< Date: @<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $priority, $date, $description From: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< ``` -------------------------------- ### ExtUtils::Install: Basic Usage Examples Source: https://perldoc.perl.org/5.42.0/-RC2/ExtUtils%3A%3AInstall Demonstrates the fundamental usage of the ExtUtils::Install module for installing, uninstalling, and converting Perl modules. ```perl use ExtUtils::Install; install({ 'blib/lib' => 'some/install/dir' }); uninstall($packlist); pm_to_blib({ 'lib/Foo/Bar.pm' => 'blib/lib/Foo/Bar.pm' }); ``` -------------------------------- ### Get Fork TTY Examples Source: https://perldoc.perl.org/5.42.0/perl5db Illustrates functions used to obtain new IN and OUT filehandles when a debugged process forks or invokes a command via `system()` that starts a new debugger. This prevents fighting over the terminal. ```perl # #GET_FORK_TTY EXAMPLE FUNCTIONS # When the process being debugged forks, or the process invokes a command via `system()` # which starts a new debugger, we need to be able to get a new `IN` and `OUT` filehandle # for the new debugger. Otherwise, the two processes fight over the terminal, and you # can never quite be sure who's going to get the input you're typing. # `get_fork_TTY` is a glob-aliased function which calls the real function that is # tasked with doing all the necessary operating system mojo to get a new TTY # (and probably another window) and to direct the new debugger to read and write there. # The debugger provides `get_fork_TTY` functions which work for TCP socket servers, # X11, OS/2, and Mac OS X. Other systems are not supported. You are encouraged to write # `get_fork_TTY` functions which work for _your_ platform and contribute them. ``` -------------------------------- ### init_INSTALL Source: https://perldoc.perl.org/5.42.0/ExtUtils%3A%3AMM_Any Sets up installation-related variables, excluding INSTALLDIRS and PREFIX. ```APIDOC ## init_INSTALL ### Description Initializes `INSTALL_*` variables and `*PREFIX` variables, with the exception of `INSTALLDIRS` and `PREFIX` themselves. ### Method sub init_INSTALL ### Endpoint N/A (Internal MakeMaker method) ### Parameters None ### Request Example ```perl $mm->init_INSTALL; ``` ### Response Modifies the MakeMaker object's internal state by setting `INSTALL_*` and `*PREFIX` variables. #### Success Response (200) * Internal variables related to installation paths and prefixes are set. ### Note This method is typically called by `init_main`. It handles cases where both `INSTALL_BASE` and `PREFIX` arguments are provided. ``` -------------------------------- ### Installing Outdated Modules (Example) Source: https://perldoc.perl.org/5.42.0/-RC3/CPAN A conceptual example showing how to programmatically install all modules that are outdated on the user's disk. This is a common operation that combines multiple CPAN functionalities. ```perl # install everything that is outdated on my disk: # (actual implementation would involve checking module versions) ``` -------------------------------- ### Perl: Initialize Installation from PREFIX Source: https://perldoc.perl.org/5.42.0/-RC2/ExtUtils%3A%3AMM_Any This Perl subroutine initializes installation paths using the PREFIX configuration. It handles defaults for man directories, executables, and scripts, falling back to system defaults or empty strings if not explicitly set. It also defines layouts for binary and man page installations. ```perl sub init_INSTALL_from_PREFIX { my $self = shift; $self->init_lib2arch; # There are often no Config.pm defaults for these new man variables so # we fall back to the old behavior which is to use installman*dir foreach my $num (1, 3) { my $k = 'installsiteman'.$num.'dir'; $self->{uc $k} ||= uc "$(installman${num}dir)" unless $Config{$k}; } foreach my $num (1, 3) { my $k = 'installvendorman'.$num.'dir'; unless( $Config{$k} ) { $self->{uc $k} ||= $Config{usevendorprefix} ? uc "$(installman${num}dir)" : ''; } } $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)' unless $Config{installsitebin}; $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)' unless $Config{installsitescript}; unless( $Config{installvendorbin} ) { $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix} ? $Config{installbin} : ''; } unless( $Config{installvendorscript} ) { $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix} ? $Config{installscript} : ''; } my $iprefix = $Config{installprefixexp} || $Config{installprefix} || $Config{prefixexp} || $Config{prefix} || ''; my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : ''; my $sprefix = $Config{siteprefixexp} || ''; # 5.005_03 doesn't have a siteprefix. $sprefix = $iprefix unless $sprefix; $self->{PREFIX} ||= ''; if( $self->{PREFIX} ) { @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} = ('$(PREFIX)') x 3; } else { $self->{PERLPREFIX} ||= $iprefix; $self->{SITEPREFIX} ||= $sprefix; $self->{VENDORPREFIX} ||= $vprefix; # Lots of MM extension authors like to use $(PREFIX) so we # put something sensible in there no matter what. $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)'; } my $arch = $Config{archname}; my $version = $Config{version}; # default style my $libstyle = $Config{installstyle} || 'lib/perl5'; my $manstyle = ''; if( $self->{LIBSTYLE} ) { $libstyle = $self->{LIBSTYLE}; $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : ''; } # Some systems, like VOS, set installman*dir to '' if they can't # read man pages. for my $num (1, 3) { $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none' unless $Config{'installman'.$num.'dir'}; } my %bin_layouts = ( bin => { s => $iprefix, t => 'perl', d => 'bin' }, vendorbin => { s => $vprefix, t => 'vendor', d => 'bin' }, sitebin => { s => $sprefix, t => 'site', d => 'bin' }, script => { s => $iprefix, t => 'perl', d => 'bin' }, vendorscript=> { s => $vprefix, t => 'vendor', d => 'bin' }, sitescript => { s => $sprefix, t => 'site', d => 'bin' }, ); my %man_layouts = ( man1dir => { s => $iprefix, t => 'perl', d => 'man/man1', style => $manstyle, }, siteman1dir => { s => $sprefix, t => 'site', d => 'man/man1', style => $manstyle, }, vendorman1dir => { s => $vprefix, t => 'vendor', d => 'man/man1', style => $manstyle, }, man3dir => { s => $iprefix, t => 'perl', d => 'man/man3', style => $manstyle, }, siteman3dir => { s => $sprefix, t => 'site', d => 'man/man3', style => $manstyle, }, vendorman3dir => { s => $vprefix, t => 'vendor', d => 'man/man3', style => $manstyle, }, ); my %lib_layouts = ( privlib => { s => $iprefix, ``` -------------------------------- ### Perl: File and Environment Variable Handling Source: https://perldoc.perl.org/5.42.0/ExtUtils%3A%3AInstall Demonstrates setting installation directories and handling quiet installation flags based on environment variables and make flags. It also includes basic file specification handling. ```perl my $INSTALL_ROOT = $ENV{PERL_INSTALL_ROOT}; my $INSTALL_QUIET = $ENV{PERL_INSTALL_QUIET}; $INSTALL_QUIET = 1 if (!exists $ENV{PERL_INSTALL_QUIET} and defined $ENV{MAKEFLAGS} and $ENV{MAKEFLAGS} =~ /\b(s|silent|quiet)\b/); my $Curdir = File::Spec->curdir; ``` -------------------------------- ### Perl: Example Usage of ExtUtils::Installed Source: https://perldoc.perl.org/5.42.0/-RC2/ExtUtils%3A%3AInstalled Demonstrates common usage patterns for the ExtUtils::Installed module, including instantiation, listing modules, validating installations, and retrieving file/directory information. ```perl use ExtUtils::Installed; my ($inst) = ExtUtils::Installed->new( skip_cwd => 1 ); my (@modules) = $inst->modules(); my (@missing) = $inst->validate("DBI"); my $all_files = $inst->files("DBI"); my $files_below_usr_local = $inst->files("DBI", "all", "/usr/local"); my $all_dirs = $inst->directories("DBI"); my $dirs_below_usr_local = $inst->directory_tree("DBI", "prog"); my $packlist = $inst->packlist("DBI"); ``` -------------------------------- ### Perl Build and Install (VMS) Source: https://perldoc.perl.org/5.42.0/perlmodinstall Instructions for building and installing Perl modules on VMS, utilizing `mms` or `mmk` for the build process. ```shell perl Makefile.PL mms test mms install ``` ```shell perl Makefile.PL mms test ``` ```shell perl Makefile.PL mmk test mmk install ``` ```shell perl Makefile.PL mmk test ``` -------------------------------- ### CPAN Shell Force Command Examples Source: https://perldoc.perl.org/5.42.0/-RC2/CPAN Illustrates the use of 'force' and 'fforce' pragmas in the CPAN shell to override default behaviors and re-execute actions like 'get', 'make', 'test', or 'install'. These commands are used to bypass cached states or failed previous attempts. ```perl cpan> force get Foo cpan> force make AUTHOR/Bar-3.14.tar.gz cpan> force test Baz cpan> force install Acme::Meta ``` -------------------------------- ### Perl B.pm Module Initialization and Exports Source: https://perldoc.perl.org/5.42.0/-RC1/B Demonstrates the initialization process of the B.pm module, including setting the version, loading XSLoader, and defining exportable constants and subroutines. It highlights the use of BEGIN blocks for setup. ```perl package B; @B::ISA = qw(Exporter); sub import { return unless scalar @_ > 1; # Called as a method call. require Exporter; B->export_to_level(1, @_); } BEGIN { $B::VERSION = '1.89'; @B::EXPORT_OK = (); require XSLoader; XSLoader::load(); } push @B::EXPORT_OK, (qw(minus_c ppname save_BEGINs class peekop cast_I32 cstring cchar hash threadsv_names main_root main_start main_cv svref_2object opnumber sub_generation amagic_generation perlstring walkoptree_slow walkoptree walkoptree_exec walksymtable parents comppadlist sv_undef compile_stats timing_info begin_av init_av check_av end_av regex_padav dowarn defstash curstash warnhook diehook inc_gv @optype @specialsv_name unitcheck_av safename)); ``` -------------------------------- ### CPAN::Module::inst_version() - Get Installed Version Source: https://perldoc.perl.org/5.42.0/-RC2/CPAN Retrieves the installed version of the module. ```perl CPAN::Module::inst_version() ``` -------------------------------- ### CPAN::Shell Setup Example Source: https://perldoc.perl.org/5.42.0/-RC1/CPAN Demonstrates the necessary steps to initialize components of CPAN before calling low-level commands programmatically. This ensures that configuration, output, and indexes are loaded correctly. ```perl CPAN::HandleConfig->load; CPAN::Shell::setup_output; CPAN::Index->reload; ``` -------------------------------- ### Get INSTALL Variables for MakeMaker Source: https://perldoc.perl.org/5.42.0/-RC2/ExtUtils%3A%3AMM_Any Retrieves a list of all INSTALL* variables, excluding the 'INSTALL' prefix. This is useful for iterating through or building sets of related variables. ```perl sub installvars { return qw(PRIVLIB SITELIB VENDORLIB ARCHLIB SITEARCH VENDORARCH BIN SITEBIN VENDORBIN SCRIPT SITESCRIPT VENDORSCRIPT MAN1DIR SITEMAN1DIR VENDORMAN1DIR MAN3DIR SITEMAN3DIR VENDORMAN3DIR ); } ``` -------------------------------- ### Configure Installation Paths Source: https://perldoc.perl.org/5.42.0/-RC3/ExtUtils%3A%3AMM_Any Defines layouts for various installation directories including 'vendorlib', 'sitelib', and 'archlib'. It includes logic to determine these paths based on the 'LIB' variable and global configuration, and a utility function 'prefixify' to construct the final installation paths. ```perl my %lib_layouts = ( perl => { s => $prefix, t => 'perl', d => '', style => $libstyle, }, vendorlib => { s => $vprefix, t => 'vendor', d => '', style => $libstyle, }, sitelib => { s => $sprefix, t => 'site', d => 'site_perl', style => $libstyle, }, archlib => { s => $iprefix, t => 'perl', d => "$version/$arch", style => $libstyle }, vendorarch => { s => $vprefix, t => 'vendor', d => "$version/$arch", style => $libstyle }, sitearch => { s => $sprefix, t => 'site', d => "site_perl/$version/$arch", style => $libstyle }, ); # Special case for LIB. if( $self->{LIB} ) { foreach my $var (keys %lib_layouts) { my $Installvar = uc "install$var"; if( $var =~ /arch/ ) { $self->{$Installvar} ||= $self->catdir($self->{LIB}, $Config{archname}); } else { $self->{$Installvar} ||= $self->{LIB}; } } } my %type2prefix = ( perl => 'PERLPREFIX', site => 'SITEPREFIX', vendor => 'VENDORPREFIX' ); my %layouts = (%bin_layouts, %man_layouts, %lib_layouts); while( my($var, $layout) = each(%layouts) ) { my($s, $t, $d, $style) = @{$layout}{qw(s t d style)}; my $r = '$('.$type2prefix{$t}.')'; warn "Prefixing $var\n" if $Verbose >= 2; my $installvar = "install$var"; my $Installvar = uc $installvar; next if $self->{$Installvar}; $d = "$style/$d" if $style; $self->prefixify($installvar, $s, $r, $d); warn " $Installvar == $self->{$Installvar}\n" if $Verbose >= 2; } # Generate these if they weren't figured out. $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH}; $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB}; return 1; } ``` -------------------------------- ### Synopsis example: Listing module files Source: https://perldoc.perl.org/5.42.0/-RC1/ExtUtils%3A%3AInstalled Illustrates how to list all files associated with a specific module (e.g., 'DBI') using the ExtUtils::Installed module. ```perl use ExtUtils::Installed; my ($inst) = ExtUtils::Installed->new( skip_cwd => 1 ); my $all_files = $inst->files("DBI"); ``` -------------------------------- ### Get Install Variables in Perl Source: https://perldoc.perl.org/5.42.0/ExtUtils%3A%3AMM_Any Retrieves a list of all INSTALL* variables, excluding the 'INSTALL' prefix. This is useful for iterating through installation settings or creating related variable sets. It requires no specific input parameters. ```perl my @installvars = $mm->installvars; ``` -------------------------------- ### Install Interface Source: https://perldoc.perl.org/5.42.0/ExtUtils%3A%3AInstall Details the parameters and behavior of the install subroutine, including handling of the $skip parameter and the introduction of the %result hash. ```APIDOC ## install ### Description Handles the installation of files, including options for skipping files, copying behavior, and tracking installation results. ### Method Subroutine (Perl) ### Parameters #### Arguments (Positional) - **$from_to** (hashref) - Required - A hash reference where keys are source files and values are their corresponding targets. - **$verbose** (integer) - Optional - If true, enables verbose output. - **$dry_run** (integer) - Optional - If true, simulates the installation without making changes. - **$uninstall_shadows** (boolean) - Optional - If true, removes shadowed files. - **$skip** (arrayref|string|boolean) - Optional - Controls which files are skipped during installation. Can be an array of patterns, a filename, or a boolean. - **$always_copy** (boolean) - Optional - If true, forces files to be copied even if unchanged. If false, copies only if changed. If undefined, uses the EU_INSTALL_ALWAYS_COPY environment variable. - **$result** (hashref) - Optional - A hash reference to populate with installation results. #### Arguments (New Style - Hash Reference) - **(reference to array of key-value pairs)** - Required - When only one argument is provided and it's an array reference, it's treated as a hash reference of options. The `from_to` key is mandatory. - **from_to** (hashref) - Mandatory - Same as the positional `$from_to` parameter. - **verbose** (integer) - Optional - Same as the positional `$verbose` parameter. - **dry_run** (integer) - Optional - Same as the positional `$dry_run` parameter. - **uninstall_shadows** (boolean) - Optional - Same as the positional `$uninstall_shadows` parameter. - **skip** (arrayref|string|boolean) - Optional - Same as the positional `$skip` parameter. - **always_copy** (boolean) - Optional - Same as the positional `$always_copy` parameter. - **result** (hashref) - Optional - Same as the positional `$result` parameter. ### Return - **(hashref)** - Returns a hash reference containing installation results if successful. If the `$result` parameter was provided, it returns the same hash reference. The hash may contain keys like `install`, `install_fail`, `install_unchanged`, `install_filtered`, `uninstall`, and `uninstall_fail`. ### Error Handling - The subroutine will `die` if any action fails when the `$result` parameter is not provided. It is recommended to pass the `$result` parameter to handle errors gracefully. ### Example ```perl # Positional argument style install( { "source/file.pm" => "blib/lib/Target/File.pm" }, 1, # verbose 0, # dry_run undef, # uninstall_shadows undef, # skip undef, # always_copy $result_hashref ); # New argument style (recommended) my $result_hashref = {}; install([ from_to => { "source/file.pm" => "blib/lib/Target/File.pm" }, verbose => 1, dry_run => 0, skip => undef, result => $result_hashref ]); ``` ``` -------------------------------- ### Initialize installation prefix and variables Source: https://perldoc.perl.org/5.42.0/-RC1/ExtUtils%3A%3AMM_Any This Perl subroutine initializes installation-related variables such as `INSTALL_*` and `*PREFIX`. It is called during the main initialization process and sets up default values for where the module components will be installed. It specifically checks for the presence of `INSTALL_BASE` and `PREFIX` arguments. ```perl sub init_INSTALL { my($self) = shift; if( $self->{ARGS}{INSTALL_BASE} and $self->{ARGS}{PREFIX} ) { ``` -------------------------------- ### HTTP::Tiny GET Request Source: https://perldoc.perl.org/5.42.0/-RC2/HTTP%3A%3ATiny Example of performing a GET request using the HTTP::Tiny client. ```APIDOC ## GET Request ### Description Performs an HTTP GET request to a specified URL. ### Method ``` get ``` ### Endpoint ``` $http->get( $url, %options ) ``` ### Parameters #### Path Parameters - **url** (string) - Required - The URL to fetch. #### Query Parameters - **options** (hashref) - Optional - Additional options for the request, such as headers, cookies, etc. ### Request Example ```perl my $response = HTTP::Tiny->new->get('http://example.com/'); ``` ### Response #### Success Response (200) Returns a hashref containing response details: - **success** (boolean) - True if the request was successful. - **status** (integer) - The HTTP status code. - **reason** (string) - The HTTP reason phrase. - **headers** (hashref) - Response headers. - **content** (string) - The response body. #### Response Example ```json { "success": true, "status": 200, "reason": "OK", "headers": { "Content-Type": "text/html" }, "content": "Hello, World!" } ``` #### Error Handling - If the request fails, `success` will be false, and `status` might be 599 for internal exceptions. ``` -------------------------------- ### Initialize Installation Paths from INSTALL_BASE in Perl Source: https://perldoc.perl.org/5.42.0/-RC1/ExtUtils%3A%3AMM_Any This Perl snippet shows how to initialize core installation paths (PREFIX, VENDORPREFIX, SITEPREFIX, PERLPREFIX) using a base path. It then iterates through various installation targets (lib, arch, bin, man directories) and constructs their full paths relative to the INSTALL_BASE. ```perl sub init_INSTALL_from_INSTALL_BASE { my $self = shift; @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} = '$(INSTALL_BASE)'; my %install; foreach my $thing (keys %map) { foreach my $dir (('', 'SITE', 'VENDOR')) { my $uc_thing = uc $thing; my $key = "INSTALL". $dir . $uc_thing; $install{$key} ||= ($thing =~ /^man.dir$/ and not $Config{lc $key}) ? 'none' : $self->catdir('$(INSTALL_BASE)', @{$map{$thing}}); } } # Adjust for variable quirks. $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH}; $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB}; foreach my $key (keys %install) { $self->$key ||= $install{$key}; } return 1; } ``` -------------------------------- ### CPAN::Module::as_glimpse() - Get Module Glimpse Source: https://perldoc.perl.org/5.42.0/-RC2/CPAN Returns a one-line summary of a module's status. The output includes installation and version information (installed and up-to-date, installable upgrade, or not installed) along with module name and maintainer details. ```perl CPAN::Module::as_glimpse() ``` -------------------------------- ### Basic XS Setup for Perlio Integration Source: https://perldoc.perl.org/5.42.0/-RC2/perlxstut Provides the essential include directives for an XS file that interacts with Perl's internals and Perlio system. It includes headers for Perl's core functions, XSUBs, and standard I/O. ```c #define PERLIO_NOT_STDIO 0 #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include ``` -------------------------------- ### ExtUtils::MM_VMS: Module Setup and Inheritance (Perl) Source: https://perldoc.perl.org/5.42.0/-RC2/ExtUtils%3A%3AMM_VMS Sets up the ExtUtils::MM_VMS module, including strict and warnings pragmas, importing necessary modules like ExtUtils::MakeMaker::Config and Exporter. It also defines version information and establishes ISA for inheritance from ExtUtils::MM_Any and ExtUtils::MM_Unix. ```perl package ExtUtils::MM_VMS; use strict; use warnings; use ExtUtils::MakeMaker::Config; require Exporter; BEGIN { # so we can compile the thing on non-VMS platforms. if( $^O eq 'VMS' ) { require VMS::Filespec; VMS::Filespec->import; } } use File::Basename; our $VERSION = '7.76'; $VERSION =~ tr/_//d; require ExtUtils::MM_Any; require ExtUtils::MM_Unix; our @ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix ); use ExtUtils::MakeMaker qw($Verbose neatvalue _sprintf562); our $Revision = $ExtUtils::MakeMaker::Revision; ``` -------------------------------- ### Get current Perl configuration Source: https://perldoc.perl.org/5.42.0/-RC1/Config%3A%3APerl%3A%3AV The myconfig function collects detailed configuration data for the current Perl installation. It utilizes Config::compile_date for newer versions or shells out to 'perl -V' for older ones. It can also optionally include environment variables starting with PERL. ```perl sub myconfig { my $args = shift; my %args = ref $args eq "HASH" ? %{$args} : ref $args eq "ARRAY" ? @{$args} : (); my $build = { %empty_build }; # 5.14.0 and later provide all the information without shelling out my $stamp = eval { Config::compile_date () }; if (defined $stamp) { $stamp =~ s/^Compiled at //; $build->{'osname'} = $^O; $build->{'stamp'} = $stamp; $build->{'patches'} = [ Config::local_patches () ]; $build->{'options'}{$_} = 1 for Config::bincompat_options (), Config::non_bincompat_options (); } else { #y $pv = qx[$^X -e"sub Config::myconfig{};" -V]; my $cnf = plv2hash (qx[$^X -V]); $build->{$_} = $cnf->{'build'}{$_} for qw( osname stamp patches options ); } my @KEYS = keys %ENV; my %env = map {( $_ => $ENV{$_} )} grep m{^PERL} => @KEYS; if ($args{'env'}) { $env{$_} = $ENV{$_} for grep m{$args{'env'}} => @KEYS; } my %config = map { $_ => $Config{$_} } @config_vars; return _make_derived ({ 'build' => $build, 'environment' => \%env, 'config' => \%config, 'derived' => {}, 'inc' => \@INC, }); } # myconfig ``` -------------------------------- ### Get Module Glimpse Information Source: https://perldoc.perl.org/5.42.0/-RC1/CPAN Returns a concise one-line summary of a module's status and information. The output includes the module's installation status (installed and up-to-date, installed but upgradable, or not installed) and maintainer/distribution details. ```perl print CPAN::Module::as_glimpse(); ``` -------------------------------- ### Net::servent Synopsis Example 1 (Perl) Source: https://perldoc.perl.org/5.42.0/-RC1/Net%3A%3Aservent Demonstrates basic usage of Net::servent by importing the module and using getservbyname to retrieve service information, then printing the service's name and port. ```perl use Net::servent; my $s = getservbyname(shift || 'ftp') || die "no service"; printf "port for %s is %s, aliases are %s\n", $s->name, $s->port, "@{$s->aliases}"; ``` -------------------------------- ### Running pod2man examples Source: https://perldoc.perl.org/5.42.0/-RC1/pod2man Demonstrates how to use the pod2man utility to convert POD files into man pages, including specifying output files and sections. ```shell pod2man program > program.1 pod2man SomeModule.pm /usr/perl/man/man3/SomeModule.3 pod2man --section=7 note.pod > note.7 ``` -------------------------------- ### Makefile.PL example for Perl module installation directories Source: https://perldoc.perl.org/5.42.0/deprecate This Perl snippet shows an example of setting 'INSTALLDIRS' in a 'Makefile.PL' file. It determines whether to install the module into the 'site' or 'perl' directories based on the Perl version, which is relevant for managing dual-life modules with the 'deprecate' pragma. ```perl WriteMakefile(( # ... INSTALLDIRS => ( "$]" >= 5.011 ? 'site' : 'perl' ), )); ``` -------------------------------- ### Install Files with Options in Perl Source: https://perldoc.perl.org/5.42.0/ExtUtils%3A%3AInstall This Perl code demonstrates file installation with verbosity, dry-run, and uninstall options. It supports skipping files based on patterns and uses packlist files for tracking installed files. ```perl install([ from_to => \%from_to, verbose => 1, dry_run => 0, uninstall_shadows => 1, skip => undef, always_copy => 1, result => \%install_results, ]); ``` -------------------------------- ### Perl format Declarations Example Source: https://perldoc.perl.org/5.42.0/-RC1/perlglossary Demonstrates the use of Perl's 'format' declarations, which are an example of WYSIWYG (What You See Is What You Get) functionality. ```perl C declarations ``` -------------------------------- ### Get INSTALL Variables from MakeMaker Source: https://perldoc.perl.org/5.42.0/-RC1/ExtUtils%3A%3AMM_Any Retrieves a list of all INSTALL* variables without the 'INSTALL' prefix. This is useful for iterating through or building related variable sets. It is part of the ExtUtils::MakeMaker module. ```perl my @installvars = $mm->installvars; ``` -------------------------------- ### Perl Module Initialization and Exporting Source: https://perldoc.perl.org/5.42.0/-RC2/B Demonstrates the standard Perl module initialization process using BEGIN blocks, XSLoader for loading C extensions, and the Exporter module for managing exported symbols. ```perl package B; @B::ISA = qw(Exporter); sub import { return unless scalar @_ > 1; require Exporter; B->export_to_level(1, @_); } BEGIN { $B::VERSION = '1.89'; @B::EXPORT_OK = (); require XSLoader; XSLoader::load(); } push @B::EXPORT_OK, (qw(minus_c ppname save_BEGINs class peekop cast_I32 cstring cchar hash threadsv_names main_root main_start main_cv svref_2object opnumber sub_generation amagic_generation perlstring walkoptree_slow walkoptree walkoptree_exec walksymtable parents comppadlist sv_undef compile_stats timing_info begin_av init_av check_av end_av regex_padav dowarn defstash curstash warnhook diehook inc_gv @optype @specialsv_name unitcheck_av safename)); ``` -------------------------------- ### Example Usage of App::Cpan Source: https://perldoc.perl.org/5.42.0/App%3A%3ACpan Provides practical examples of how to use the `cpan` command for common tasks like printing help, checking versions, creating autobundles, and recompiling modules. ```shell cpan -h ``` ```shell cpan -v ``` ```shell cpan -a ``` ```shell cpan -r ``` ```shell cpan -u ```