Your IP : 216.73.216.21


Current Path : /pkg/perl/.plenv/plugins/perl-build/lib/Perl/Build/
Upload File :
Current File : //pkg/perl/.plenv/plugins/perl-build/lib/Perl/Build/Built.pm

package Perl::Build::Built;

use strict;
use warnings;
use utf8;

use 5.008001;
our $VERSION = '1.34';

use Carp ();
use File::Spec::Functions qw( catdir catfile );

sub run_env {
    my ( $self, @args ) = @_;
    my $config = {};
    if ( ref $args[0] eq 'HASH' ) {
        $config = %{ shift @args };
    }
    if ( $args[0] and ref $args[0] eq 'CODE' ) {
        $config->{code} = shift @args;
    }
    if (@args) {
        Carp::croak( '->run_env(\%config,\&code)'
              . ' or ->run_env(\&code)'
              . ' or ->run_env(\%config)' );
    }
    local $ENV{PATH} = $self->combined_bin_path;
    my $combined_man_path = $self->combined_man_path;
    local $ENV{MANPATH} = $combined_man_path if $combined_man_path;
    delete local $ENV{PERL5LIB};
    return $config->{code}->();
}

sub new {
    my ( $self, $args ) = @_;
    $args = {} unless defined $args;
    Carp::croak '->new(\%config) required' if not ref $args eq 'HASH';
    Carp::croak 'installed_path is a mandatory parameter'
      unless exists $args->{installed_path};
    return bless $args, $self;
}

sub installed_path {
    return $_[0]->{installed_path};
}

sub bin_path {
    return catdir( $_[0]->{installed_path}, 'bin' );
}

sub man_path {
    return catdir( $_[0]->{installed_path}, 'man' );
}

sub combined_bin_path {
    return $_[0]->bin_path . ':' . $ENV{PATH};
}

sub combined_man_path {
    if ( -d $_[0]->man_path ) {
        return $_[0]->man_path . ':' . $ENV{MANPATH};
    }
    return $ENV{MANPATH};
}

1;

__END__

=pod

=encoding utf8

=for stopwords dir

=head1 NAME

Perl::Build::Built - A utility class to work with recently built perl installs.

=head1 SYNOPSIS

    my $result = Perl::Build->install( ... );
    $result->run_env(sub{
        # Run code on the installed perl
        system('perl', .... );
    });

=head1 METHODS

=over 4

=item $instance->run_env(\&code)

Run C<&code> inside an environment configured to use the built perl.

    $instance->run_env(sub{
        my $cpanm_path = catfile( $instance->bin_path , 'cpanm' );
        system('wget','-O', $cpanm_path, 'http://path/to/cpanm');
        system('chmod', 'u+x', $cpanm_path );
        system('cpanm', "App::cpanoutdated");
        system('perl',.... );
    });

=item Perl::Build::Built->new( \%params )

You probably don't need to call this, ever.

=item $instance->installed_path

Returns the path the Perl was installed to ( Just whatever was passed to C<new> )

=item $instance->bin_path

Returns the path to the 'bin' dir inside the installed Perl target directory.

=item $instance->man_path

Returns the path to the 'man' dir inside the installed Perl target directory.

=item $instance->combined_bin_path

C<bin_path> prefixed onto C<$ENV{PATH}>

=item $instance->combined_man_path

C<man_path> prefixed onto C<$ENV{MANPATH}>

=back

=head1 AUTHOR

=over 4

=item Kent Fredric E<lt>kentnl@cpan.orgE<gt>

=item Tokuhiro Matsuno E<lt>tokuhirom@gmail.comE<gt>

=back

=head1 LICENSE

Copyright (C) Tokuhiro Matsuno

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.


https://nalibali.org/post-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/page-sitemap.xml 2026-11-18T09:24:11+00:00 https://nalibali.org/stories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/stories-sitemap2.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/audio_stories-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/story_cards-sitemap.xml 2025-06-06T10:27:48+00:00 https://nalibali.org/story_seeds-sitemap.xml 2025-05-19T07:35:43+00:00 https://nalibali.org/rhymes-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/activity_sheets-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/team_member-sitemap.xml 2025-05-28T09:40:43+00:00 https://nalibali.org/video_stories-sitemap.xml 2025-06-23T08:48:28+00:00 https://nalibali.org/guides-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/story_supplements-sitemap.xml 2025-09-16T12:22:20+00:00 https://nalibali.org/vacancies-sitemap.xml 2026-09-17T07:05:01+00:00 https://nalibali.org/category-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/post_tag-sitemap.xml 2026-11-06T00:00:00+00:00 https://nalibali.org/test-sitemap.xml 2025-06-13T09:36:28+00:00 https://nalibali.org/story_categories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/activity_sheets_categories-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables_categories-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks_categories-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/single_audio-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/rhyme_categories-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/guide_categories-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/author-sitemap.xml 2026-01-22T07:26:07+00:00