App-cpanminus
view release on metacpan or search on metacpan
lib/App/cpanminus/fatscript.pm view on Meta::CPAN
unless -r $file;
my $self;
eval {
my $struct = Parse::CPAN::Meta->load_file( $file );
$self = $class->_new($struct, $options);
};
croak($@) if $@;
return $self;
}
#pod =method load_yaml_string
#pod
#pod my $meta = CPAN::Meta->load_yaml_string($yaml, \%options);
#pod
#pod This method returns a new CPAN::Meta object using the first document in the
#pod given YAML string. In other respects it is identical to C<load_file()>.
#pod
#pod =cut
sub load_yaml_string {
my ($class, $yaml, $options) = @_;
$options->{lazy_validation} = 1 unless exists $options->{lazy_validation};
my $self;
eval {
my ($struct) = Parse::CPAN::Meta->load_yaml_string( $yaml );
$self = $class->_new($struct, $options);
};
croak($@) if $@;
return $self;
}
#pod =method load_json_string
#pod
#pod my $meta = CPAN::Meta->load_json_string($json, \%options);
#pod
#pod This method returns a new CPAN::Meta object using the structure represented by
#pod the given JSON string. In other respects it is identical to C<load_file()>.
#pod
#pod =cut
sub load_json_string {
my ($class, $json, $options) = @_;
$options->{lazy_validation} = 1 unless exists $options->{lazy_validation};
my $self;
eval {
my $struct = Parse::CPAN::Meta->load_json_string( $json );
$self = $class->_new($struct, $options);
};
croak($@) if $@;
return $self;
}
#pod =method load_string
#pod
#pod my $meta = CPAN::Meta->load_string($string, \%options);
#pod
#pod If you don't know if a string contains YAML or JSON, this method will use
#pod L<Parse::CPAN::Meta> to guess. In other respects it is identical to
#pod C<load_file()>.
#pod
#pod =cut
sub load_string {
my ($class, $string, $options) = @_;
$options->{lazy_validation} = 1 unless exists $options->{lazy_validation};
my $self;
eval {
my $struct = Parse::CPAN::Meta->load_string( $string );
$self = $class->_new($struct, $options);
};
croak($@) if $@;
return $self;
}
#pod =method save
#pod
#pod $meta->save($distmeta_file, \%options);
#pod
#pod Serializes the object as JSON and writes it to the given file. The only valid
#pod option is C<version>, which defaults to '2'. On Perl 5.8.1 or later, the file
#pod is saved with UTF-8 encoding.
#pod
#pod For C<version> 2 (or higher), the filename should end in '.json'. L<JSON::PP>
#pod is the default JSON backend. Using another JSON backend requires L<JSON> 2.5 or
#pod later and you must set the C<$ENV{PERL_JSON_BACKEND}> to a supported alternate
#pod backend like L<JSON::XS>.
#pod
#pod For C<version> less than 2, the filename should end in '.yml'.
#pod L<CPAN::Meta::Converter> is used to generate an older metadata structure, which
#pod is serialized to YAML. CPAN::Meta::YAML is the default YAML backend. You may
#pod set the C<$ENV{PERL_YAML_BACKEND}> to a supported alternative backend, though
#pod this is not recommended due to subtle incompatibilities between YAML parsers on
#pod CPAN.
#pod
#pod =cut
sub save {
my ($self, $file, $options) = @_;
my $version = $options->{version} || '2';
my $layer = $] ge '5.008001' ? ':utf8' : '';
if ( $version ge '2' ) {
carp "'$file' should end in '.json'"
unless $file =~ m{\.json$};
}
else {
carp "'$file' should end in '.yml'"
unless $file =~ m{\.yml$};
}
my $data = $self->as_string( $options );
open my $fh, ">$layer", $file
or die "Error opening '$file' for writing: $!\n";
print {$fh} $data;
close $fh
lib/App/cpanminus/fatscript.pm view on Meta::CPAN
my $meta = CPAN::Meta->new($distmeta_struct, \%options);
Returns a valid CPAN::Meta object or dies if the supplied metadata hash
reference fails to validate. Older-format metadata will be up-converted to
version 2 if they validate against the original stated specification.
It takes an optional hashref of options. Valid options include:
=over
=item *
lazy_validation -- if true, new will attempt to convert the given metadata
to version 2 before attempting to validate it. This means than any
fixable errors will be handled by CPAN::Meta::Converter before validation.
(Note that this might result in invalid optional data being silently
dropped.) The default is false.
=back
=head2 create
my $meta = CPAN::Meta->create($distmeta_struct, \%options);
This is same as C<new()>, except that C<generated_by> and C<meta-spec> fields
will be generated if not provided. This means the metadata structure is
assumed to otherwise follow the latest L<CPAN::Meta::Spec>.
=head2 load_file
my $meta = CPAN::Meta->load_file($distmeta_file, \%options);
Given a pathname to a file containing metadata, this deserializes the file
according to its file suffix and constructs a new C<CPAN::Meta> object, just
like C<new()>. It will die if the deserialized version fails to validate
against its stated specification version.
It takes the same options as C<new()> but C<lazy_validation> defaults to
true.
=head2 load_yaml_string
my $meta = CPAN::Meta->load_yaml_string($yaml, \%options);
This method returns a new CPAN::Meta object using the first document in the
given YAML string. In other respects it is identical to C<load_file()>.
=head2 load_json_string
my $meta = CPAN::Meta->load_json_string($json, \%options);
This method returns a new CPAN::Meta object using the structure represented by
the given JSON string. In other respects it is identical to C<load_file()>.
=head2 load_string
my $meta = CPAN::Meta->load_string($string, \%options);
If you don't know if a string contains YAML or JSON, this method will use
L<Parse::CPAN::Meta> to guess. In other respects it is identical to
C<load_file()>.
=head2 save
$meta->save($distmeta_file, \%options);
Serializes the object as JSON and writes it to the given file. The only valid
option is C<version>, which defaults to '2'. On Perl 5.8.1 or later, the file
is saved with UTF-8 encoding.
For C<version> 2 (or higher), the filename should end in '.json'. L<JSON::PP>
is the default JSON backend. Using another JSON backend requires L<JSON> 2.5 or
later and you must set the C<$ENV{PERL_JSON_BACKEND}> to a supported alternate
backend like L<JSON::XS>.
For C<version> less than 2, the filename should end in '.yml'.
L<CPAN::Meta::Converter> is used to generate an older metadata structure, which
is serialized to YAML. CPAN::Meta::YAML is the default YAML backend. You may
set the C<$ENV{PERL_YAML_BACKEND}> to a supported alternative backend, though
this is not recommended due to subtle incompatibilities between YAML parsers on
CPAN.
=head2 meta_spec_version
This method returns the version part of the C<meta_spec> entry in the distmeta
structure. It is equivalent to:
$meta->meta_spec->{version};
=head2 effective_prereqs
my $prereqs = $meta->effective_prereqs;
my $prereqs = $meta->effective_prereqs( \@feature_identifiers );
This method returns a L<CPAN::Meta::Prereqs> object describing all the
prereqs for the distribution. If an arrayref of feature identifiers is given,
the prereqs for the identified features are merged together with the
distribution's core prereqs before the CPAN::Meta::Prereqs object is returned.
=head2 should_index_file
... if $meta->should_index_file( $filename );
This method returns true if the given file should be indexed. It decides this
by checking the C<file> and C<directory> keys in the C<no_index> property of
the distmeta structure. Note that neither the version format nor
C<release_status> are considered.
C<$filename> should be given in unix format.
=head2 should_index_package
... if $meta->should_index_package( $package );
This method returns true if the given package should be indexed. It decides
this by checking the C<package> and C<namespace> keys in the C<no_index>
property of the distmeta structure. Note that neither the version format nor
C<release_status> are considered.
lib/App/cpanminus/fatscript.pm view on Meta::CPAN
# OO-interface
$coder = JSON::PP->new->ascii->pretty->allow_nonref;
$json_text = $json->encode( $perl_scalar );
$perl_scalar = $json->decode( $json_text );
$pretty_printed = $json->pretty->encode( $perl_scalar ); # pretty-printing
# Note that JSON version 2.0 and above will automatically use
# JSON::XS or JSON::PP, so you should be able to just:
use JSON;
=head1 VERSION
2.27300
L<JSON::XS> 2.27 (~2.30) compatible.
=head1 NOTE
JSON::PP had been inculded in JSON distribution (CPAN module).
It was a perl core module in Perl 5.14.
=head1 DESCRIPTION
This module is L<JSON::XS> compatible pure Perl module.
(Perl 5.8 or later is recommended)
JSON::XS is the fastest and most proper JSON module on CPAN.
It is written by Marc Lehmann in C, so must be compiled and
installed in the used environment.
JSON::PP is a pure-Perl module and has compatibility to JSON::XS.
=head2 FEATURES
=over
=item * correct unicode handling
This module knows how to handle Unicode (depending on Perl version).
See to L<JSON::XS/A FEW NOTES ON UNICODE AND PERL> and L<UNICODE HANDLING ON PERLS>.
=item * round-trip integrity
When you serialise a perl data structure using only data types supported
by JSON and Perl, the deserialised data structure is identical on the Perl
level. (e.g. the string "2.0" doesn't suddenly become "2" just because
it looks like a number). There I<are> minor exceptions to this, read the
MAPPING section below to learn about those.
=item * strict checking of JSON correctness
There is no guessing, no generating of illegal JSON texts by default,
and only JSON is accepted as input by default (the latter is a security feature).
But when some options are set, loose chcking features are available.
=back
=head1 FUNCTIONAL INTERFACE
Some documents are copied and modified from L<JSON::XS/FUNCTIONAL INTERFACE>.
=head2 encode_json
$json_text = encode_json $perl_scalar
Converts the given Perl data structure to a UTF-8 encoded, binary string.
This function call is functionally identical to:
$json_text = JSON::PP->new->utf8->encode($perl_scalar)
=head2 decode_json
$perl_scalar = decode_json $json_text
The opposite of C<encode_json>: expects an UTF-8 (binary) string and tries
to parse that as an UTF-8 encoded JSON text, returning the resulting
reference.
This function call is functionally identical to:
$perl_scalar = JSON::PP->new->utf8->decode($json_text)
=head2 JSON::PP::is_bool
$is_boolean = JSON::PP::is_bool($scalar)
Returns true if the passed scalar represents either JSON::PP::true or
JSON::PP::false, two constants that act like C<1> and C<0> respectively
and are also used to represent JSON C<true> and C<false> in Perl strings.
=head2 JSON::PP::true
Returns JSON true value which is blessed object.
It C<isa> JSON::PP::Boolean object.
=head2 JSON::PP::false
Returns JSON false value which is blessed object.
It C<isa> JSON::PP::Boolean object.
=head2 JSON::PP::null
Returns C<undef>.
See L<MAPPING>, below, for more information on how JSON values are mapped to
Perl.
=head1 HOW DO I DECODE A DATA FROM OUTER AND ENCODE TO OUTER
This section supposes that your perl vresion is 5.8 or later.
lib/App/cpanminus/fatscript.pm view on Meta::CPAN
=item number
A JSON number becomes either an integer, numeric (floating point) or
string scalar in perl, depending on its range and any fractional parts. On
the Perl level, there is no difference between those as Perl handles all
the conversion details, but an integer may take slightly less memory and
might represent more values exactly than floating point numbers.
If the number consists of digits only, C<JSON> will try to represent
it as an integer value. If that fails, it will try to represent it as
a numeric (floating point) value if that is possible without loss of
precision. Otherwise it will preserve the number as a string value (in
which case you lose roundtripping ability, as the JSON number will be
re-encoded toa JSON string).
Numbers containing a fractional or exponential part will always be
represented as numeric (floating point) values, possibly at a loss of
precision (in which case you might lose perfect roundtripping ability, but
the JSON number will still be re-encoded as a JSON number).
Note that precision is not accuracy - binary floating point values cannot
represent most decimal fractions exactly, and when converting from and to
floating point, C<JSON> only guarantees precision up to but not including
the leats significant bit.
When C<allow_bignum> is enable, the big integers
and the numeric can be optionally converted into L<Math::BigInt> and
L<Math::BigFloat> objects.
=item true, false
These JSON atoms become C<JSON::PP::true> and C<JSON::PP::false>,
respectively. They are overloaded to act almost exactly like the numbers
C<1> and C<0>. You can check wether a scalar is a JSON boolean by using
the C<JSON::is_bool> function.
print JSON::PP::true . "\n";
=> true
print JSON::PP::true + 1;
=> 1
ok(JSON::true eq '1');
ok(JSON::true == 1);
C<JSON> will install these missing overloading features to the backend modules.
=item null
A JSON null atom becomes C<undef> in Perl.
C<JSON::PP::null> returns C<unddef>.
=back
=head2 PERL -> JSON
The mapping from Perl to JSON is slightly more difficult, as Perl is a
truly typeless language, so we can only guess which JSON type is meant by
a Perl value.
=over 4
=item hash references
Perl hash references become JSON objects. As there is no inherent ordering
in hash keys (or JSON objects), they will usually be encoded in a
pseudo-random order that can change between runs of the same program but
stays generally the same within a single run of a program. C<JSON>
optionally sort the hash keys (determined by the I<canonical> flag), so
the same datastructure will serialise to the same JSON text (given same
settings and version of JSON::XS), but this incurs a runtime overhead
and is only rarely useful, e.g. when you want to compare some JSON text
against another for equality.
=item array references
Perl array references become JSON arrays.
=item other references
Other unblessed references are generally not allowed and will cause an
exception to be thrown, except for references to the integers C<0> and
C<1>, which get turned into C<false> and C<true> atoms in JSON. You can
also use C<JSON::false> and C<JSON::true> to improve readability.
to_json [\0,JSON::PP::true] # yields [false,true]
=item JSON::PP::true, JSON::PP::false, JSON::PP::null
These special values become JSON true and JSON false values,
respectively. You can also use C<\1> and C<\0> directly if you want.
JSON::PP::null returns C<undef>.
=item blessed objects
Blessed objects are not directly representable in JSON. See the
C<allow_blessed> and C<convert_blessed> methods on various options on
how to deal with this: basically, you can choose between throwing an
exception, encoding the reference as if it weren't blessed, or provide
your own serialiser method.
See to L<convert_blessed>.
=item simple scalars
Simple Perl scalars (any scalar that is not a reference) are the most
difficult objects to encode: JSON::XS and JSON::PP will encode undefined scalars as
JSON C<null> values, scalars that have last been used in a string context
before encoding as JSON strings, and anything else as number value:
# dump as number
encode_json [2] # yields [2]
encode_json [-3.0e17] # yields [-3e+17]
my $value = 5; encode_json [$value] # yields [5]
# used as string, so dump as string
lib/App/cpanminus/fatscript.pm view on Meta::CPAN
C<files>.
=item files
Array reference of files to examine. May not be specified with C<dir>.
=item prefix
String to prepend to the C<file> field of the resulting output. This defaults
to F<lib>, which is the common case for most CPAN distributions with their
F<.pm> files in F<lib>. This option ensures the META information has the
correct relative path even when the C<dir> or C<files> arguments are
absolute or have relative paths from a location other than the distribution
root.
=back
For example, given C<dir> of 'lib' and C<prefix> of 'lib', the return value
is a hashref of the form:
{
'Package::Name' => {
version => '0.123',
file => 'lib/Package/Name.pm'
},
'OtherPackage::Name' => ...
}
=head2 C<< package_versions_from_directory($dir, \@files?) >>
Scans C<$dir> for .pm files (unless C<@files> is given, in which case looks
for those files in C<$dir> - and reads each file for packages and versions,
returning a hashref of the form:
{
'Package::Name' => {
version => '0.123',
file => 'Package/Name.pm'
},
'OtherPackage::Name' => ...
}
The C<DB> and C<main> packages are always omitted, as are any "private"
packages that have leading underscores in the namespace (e.g.
C<Foo::_private>)
Note that the file path is relative to C<$dir> if that is specified.
This B<must not> be used directly for CPAN META C<provides>. See
the C<provides> method instead.
=head2 C<< log_info (internal) >>
Used internally to perform logging; imported from Log::Contextual if
Log::Contextual has already been loaded, otherwise simply calls warn.
=head1 OBJECT METHODS
=head2 C<< name() >>
Returns the name of the package represented by this module. If there
is more than one package, it makes a best guess based on the
filename. If it's a script (i.e. not a *.pm) the package name is
'main'.
=head2 C<< version($package) >>
Returns the version as defined by the $VERSION variable for the
package as returned by the C<name> method if no arguments are
given. If given the name of a package it will attempt to return the
version of that package if it is specified in the file.
=head2 C<< filename() >>
Returns the absolute path to the file.
Note that this file may not actually exist on disk yet, e.g. if the module was read from an in-memory filehandle.
=head2 C<< packages_inside() >>
Returns a list of packages. Note: this is a raw list of packages
discovered (or assumed, in the case of C<main>). It is not
filtered for C<DB>, C<main> or private packages the way the
C<provides> method does. Invalid package names are not returned,
for example "Foo:Bar". Strange but valid package names are
returned, for example "Foo::Bar::", and are left up to the caller
on how to handle.
=head2 C<< pod_inside() >>
Returns a list of POD sections.
=head2 C<< contains_pod() >>
Returns true if there is any POD in the file.
=head2 C<< pod($section) >>
Returns the POD data in the given section.
=head2 C<< is_indexable($package) >> or C<< is_indexable() >>
Available since version 1.000020.
Returns a boolean indicating whether the package (if provided) or any package
(otherwise) is eligible for indexing by PAUSE, the Perl Authors Upload Server.
Note This only checks for valid C<package> declarations, and does not take any
ownership information into account.
=head1 SUPPORT
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Module-Metadata>
(or L<bug-Module-Metadata@rt.cpan.org|mailto:bug-Module-Metadata@rt.cpan.org>).
There is also a mailing list available for users of this distribution, at
L<http://lists.perl.org/list/cpan-workers.html>.
There is also an irc channel available for users of this distribution, at
L<C<#toolchain> on C<irc.perl.org>|irc://irc.perl.org/#toolchain>.
=head1 AUTHOR
Original code from Module::Build::ModuleInfo by Ken Williams
lib/App/cpanminus/fatscript.pm view on Meta::CPAN
=head1 DESCRIPTION
B<Parse::CPAN::Meta> is a parser for F<META.json> and F<META.yml> files, using
L<JSON::PP> and/or L<CPAN::Meta::YAML>.
B<Parse::CPAN::Meta> provides three methods: C<load_file>, C<load_json_string>,
and C<load_yaml_string>. These will read and deserialize CPAN metafiles, and
are described below in detail.
B<Parse::CPAN::Meta> provides a legacy API of only two functions,
based on the YAML functions of the same name. Wherever possible,
identical calling semantics are used. These may only be used with YAML sources.
All error reporting is done with exceptions (die'ing).
Note that META files are expected to be in UTF-8 encoding, only. When
converted string data, it must first be decoded from UTF-8.
=begin Pod::Coverage
=end Pod::Coverage
=head1 METHODS
=head2 load_file
my $metadata_structure = Parse::CPAN::Meta->load_file('META.json');
my $metadata_structure = Parse::CPAN::Meta->load_file('META.yml');
This method will read the named file and deserialize it to a data structure,
determining whether it should be JSON or YAML based on the filename.
The file will be read using the ":utf8" IO layer.
=head2 load_yaml_string
my $metadata_structure = Parse::CPAN::Meta->load_yaml_string($yaml_string);
This method deserializes the given string of YAML and returns the first
document in it. (CPAN metadata files should always have only one document.)
If the source was UTF-8 encoded, the string must be decoded before calling
C<load_yaml_string>.
=head2 load_json_string
my $metadata_structure = Parse::CPAN::Meta->load_json_string($json_string);
This method deserializes the given string of JSON and the result.
If the source was UTF-8 encoded, the string must be decoded before calling
C<load_json_string>.
=head2 load_string
my $metadata_structure = Parse::CPAN::Meta->load_string($some_string);
If you don't know whether a string contains YAML or JSON data, this method
will use some heuristics and guess. If it can't tell, it assumes YAML.
=head2 yaml_backend
my $backend = Parse::CPAN::Meta->yaml_backend;
Returns the module name of the YAML serializer. See L</ENVIRONMENT>
for details.
=head2 json_backend
my $backend = Parse::CPAN::Meta->json_backend;
Returns the module name of the JSON serializer. This will either
be L<JSON::PP> or L<JSON>. Even if C<PERL_JSON_BACKEND> is set,
this will return L<JSON> as further delegation is handled by
the L<JSON> module. See L</ENVIRONMENT> for details.
=head1 FUNCTIONS
For maintenance clarity, no functions are exported by default. These functions
are available for backwards compatibility only and are best avoided in favor of
C<load_file>.
=head2 Load
my @yaml = Parse::CPAN::Meta::Load( $string );
Parses a string containing a valid YAML stream into a list of Perl data
structures.
=head2 LoadFile
my @yaml = Parse::CPAN::Meta::LoadFile( 'META.yml' );
Reads the YAML stream from a file instead of a string.
=head1 ENVIRONMENT
=head2 PERL_JSON_BACKEND
By default, L<JSON::PP> will be used for deserializing JSON data. If the
C<PERL_JSON_BACKEND> environment variable exists, is true and is not
"JSON::PP", then the L<JSON> module (version 2.5 or greater) will be loaded and
used to interpret C<PERL_JSON_BACKEND>. If L<JSON> is not installed or is too
old, an exception will be thrown.
=head2 PERL_YAML_BACKEND
By default, L<CPAN::Meta::YAML> will be used for deserializing YAML data. If
the C<PERL_YAML_BACKEND> environment variable is defined, then it is interpreted
as a module to use for deserialization. The given module must be installed,
must load correctly and must implement the C<Load()> function or an exception
will be thrown.
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
=head1 SUPPORT
=head2 Bugs / Feature Requests
lib/App/cpanminus/fatscript.pm view on Meta::CPAN
}
sub build_deact_all_environment_vars_for {
my $self = $_[0]->new->deactivate_all;
$self->build_environment_vars;
}
sub build_environment_vars {
my $self = shift;
(
PATH => join($_path_sep, _as_list($self->bins)),
PERL5LIB => join($_path_sep, _as_list($self->libs)),
PERL_LOCAL_LIB_ROOT => join($_path_sep, _as_list($self->roots)),
%{$self->extra},
);
}
sub setup_local_lib_for {
my $self = $_[0]->new->activate($_[1]);
$self->setup_local_lib;
}
sub setup_local_lib {
my $self = shift;
# if Carp is already loaded, ensure Carp::Heavy is also loaded, to avoid
# $VERSION mismatch errors (Carp::Heavy loads Carp, so we do not need to
# check in the other direction)
require Carp::Heavy if $INC{'Carp.pm'};
$self->setup_env_hash;
@INC = @{$self->inc};
}
sub setup_env_hash_for {
my $self = $_[0]->new->activate($_[1]);
$self->setup_env_hash;
}
sub setup_env_hash {
my $self = shift;
my %env = $self->build_environment_vars;
for my $key (keys %env) {
if (defined $env{$key}) {
$ENV{$key} = $env{$key};
}
else {
delete $ENV{$key};
}
}
}
sub print_environment_vars_for {
print $_[0]->environment_vars_string_for(@_[1..$#_]);
}
sub environment_vars_string_for {
my $self = $_[0]->new->activate($_[1]);
$self->environment_vars_string;
}
sub environment_vars_string {
my ($self, $shelltype) = @_;
$shelltype ||= $self->guess_shelltype;
my $extra = $self->extra;
my @envs = (
PATH => $self->bins,
PERL5LIB => $self->libs,
PERL_LOCAL_LIB_ROOT => $self->roots,
map { $_ => $extra->{$_} } sort keys %$extra,
);
$self->_build_env_string($shelltype, \@envs);
}
sub _build_env_string {
my ($self, $shelltype, $envs) = @_;
my @envs = @$envs;
my $build_method = "build_${shelltype}_env_declaration";
my $out = '';
while (@envs) {
my ($name, $value) = (shift(@envs), shift(@envs));
if (
ref $value
&& @$value == 1
&& ref $value->[0]
&& ref $value->[0] eq 'SCALAR'
&& ${$value->[0]} eq $name) {
next;
}
$out .= $self->$build_method($name, $value);
}
my $wrap_method = "wrap_${shelltype}_output";
if ($self->can($wrap_method)) {
return $self->$wrap_method($out);
}
return $out;
}
sub build_bourne_env_declaration {
my ($class, $name, $args) = @_;
my $value = $class->_interpolate($args, '${%s}', qr/["\\\$!`]/, '\\%s');
if (!defined $value) {
return qq{unset $name;\n};
}
$value =~ s/(^|\G|$_path_sep)\$\{$name\}$_path_sep/$1\${$name}\${$name+$_path_sep}/g;
$value =~ s/$_path_sep\$\{$name\}$/\${$name+$_path_sep}\${$name}/;
qq{${name}="$value"; export ${name};\n}
}
sub build_csh_env_declaration {
my ($class, $name, $args) = @_;
my ($value, @vars) = $class->_interpolate($args, '${%s}', '"', '"\\%s"');
if (!defined $value) {
return qq{unsetenv $name;\n};
}
my $out = '';
for my $var (@vars) {
lib/App/cpanminus/fatscript.pm view on Meta::CPAN
resolve_home_path
resolve_empty_path
)}($path);
$path;
}
sub resolve_empty_path {
my ($class, $path) = @_;
if (defined $path) {
$path;
} else {
'~/perl5';
}
}
sub resolve_home_path {
my ($class, $path) = @_;
$path =~ /^~([^\/]*)/ or return $path;
my $user = $1;
my $homedir = do {
if (! length($user) && defined $ENV{HOME}) {
$ENV{HOME};
}
else {
require File::Glob;
File::Glob::bsd_glob("~$user", File::Glob::GLOB_TILDE());
}
};
unless (defined $homedir) {
require Carp; require Carp::Heavy;
Carp::croak(
"Couldn't resolve homedir for "
.(defined $user ? $user : 'current user')
);
}
$path =~ s/^~[^\/]*/$homedir/;
$path;
}
sub resolve_relative_path {
my ($class, $path) = @_;
_rel2abs($path);
}
sub ensure_dir_structure_for {
my ($class, $path) = @_;
unless (-d $path) {
warn "Attempting to create directory ${path}\n";
}
require File::Basename;
my @dirs;
while(!-d $path) {
push @dirs, $path;
$path = File::Basename::dirname($path);
}
mkdir $_ for reverse @dirs;
return;
}
sub guess_shelltype {
my $shellbin
= defined $ENV{SHELL}
? ($ENV{SHELL} =~ /([\w.]+)$/)[-1]
: ( $^O eq 'MSWin32' && exists $ENV{'!EXITCODE'} )
? 'bash'
: ( $^O eq 'MSWin32' && $ENV{PROMPT} && $ENV{COMSPEC} )
? ($ENV{COMSPEC} =~ /([\w.]+)$/)[-1]
: ( $^O eq 'MSWin32' && !$ENV{PROMPT} )
? 'powershell.exe'
: 'sh';
for ($shellbin) {
return
/csh$/ ? 'csh'
: /fish/ ? 'fish'
: /command(?:\.com)?$/i ? 'cmd'
: /cmd(?:\.exe)?$/i ? 'cmd'
: /4nt(?:\.exe)?$/i ? 'cmd'
: /powershell(?:\.exe)?$/i ? 'powershell'
: 'bourne';
}
}
1;
__END__
=encoding utf8
=head1 NAME
local::lib - create and use a local lib/ for perl modules with PERL5LIB
=head1 SYNOPSIS
In code -
use local::lib; # sets up a local lib at ~/perl5
use local::lib '~/foo'; # same, but ~/foo
# Or...
use FindBin;
use local::lib "$FindBin::Bin/../support"; # app-local support library
From the shell -
# Install LWP and its missing dependencies to the '~/perl5' directory
perl -MCPAN -Mlocal::lib -e 'CPAN::install(LWP)'
# Just print out useful shell commands
$ perl -Mlocal::lib
PERL_MB_OPT='--install_base /home/username/perl5'; export PERL_MB_OPT;
PERL_MM_OPT='INSTALL_BASE=/home/username/perl5'; export PERL_MM_OPT;
PERL5LIB="/home/username/perl5/lib/perl5"; export PERL5LIB;
PATH="/home/username/perl5/bin:$PATH"; export PATH;
PERL_LOCAL_LIB_ROOT="/home/usename/perl5:$PERL_LOCAL_LIB_ROOT"; export PERL_LOCAL_LIB_ROOT;
From a .bashrc file -
[ $SHLVL -eq 1 ] && eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"
( run in 1.368 second using v1.01-cache-2.11-cpan-39bf76dae61 )