/usr/share/perl5/Padre/CPAN.pm is in padre 1.00+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | package Padre::CPAN;
use 5.008;
use strict;
use warnings;
use File::Spec ();
use File::HomeDir ();
use Padre::Wx ();
our $VERSION = '1.00';
######################################################################
# Integration with CPAN.pm
my $SINGLETON = undef;
sub new {
my $class = shift;
unless ($SINGLETON) {
require CPAN;
$SINGLETON = bless {}, $class;
CPAN::HandleConfig->load(
be_silent => 1,
);
$SINGLETON->{modules} = [ map { $_->id } CPAN::Shell->expand( 'Module', '/^/' ) ];
}
return $SINGLETON;
}
sub get_modules {
my $self = shift;
my $regex = shift;
$regex ||= '^';
$regex =~ s/ //g;
my $MAX_DISPLAY = 100;
my $i = 0;
my @modules;
foreach my $module ( @{ $self->{modules} } ) {
next if $module !~ /$regex/i;
$i++;
last if $i > $MAX_DISPLAY;
push @modules, $module;
}
return \@modules;
}
sub cpan_config {
my $class = shift;
my $main = shift;
# Locate the CPAN config file(s)
my $default_dir = '';
eval {
require CPAN;
$default_dir = $INC{'CPAN.pm'};
$default_dir =~ s/\.pm$//is; # remove .pm
};
# Load the main config first
if ( $default_dir ne '' ) {
my $core = File::Spec->catfile( $default_dir, 'Config.pm' );
if ( -e $core ) {
$main->setup_editors($core);
return;
}
}
# Fallback to a personal config
my $user = File::Spec->catfile(
File::HomeDir->my_home,
'.cpan', 'CPAN', 'MyConfig.pm'
);
if ( -e $user ) {
$main->setup_editors($user);
return;
}
$main->error( Wx::gettext('Failed to find your CPAN configuration') );
}
######################################################################
# Integration with cpanm
sub install_file {
my $class = shift;
my $main = shift;
# Ask what we should install
my $dialog = Wx::FileDialog->new(
$main,
Wx::gettext('Select distribution to install'),
'', # Default directory
'', # Default file
'CPAN Packages (*.tar.gz)|*.tar.gz', # wildcard
Wx::FD_OPEN | Wx::FD_FILE_MUST_EXIST
);
$dialog->CentreOnParent;
if ( $dialog->ShowModal == Wx::ID_CANCEL ) {
return;
}
my $string = $dialog->GetPath;
$dialog->Destroy;
unless ( defined $string and $string =~ /\S/ ) {
$main->error( Wx::gettext('Did not provide a distribution') );
return;
}
$class->install_cpanm( $main, $string );
}
sub install_url {
my $class = shift;
my $main = shift;
# Ask what we should install
my $dialog = Wx::TextEntryDialog->new(
$main,
Wx::gettext("Enter URL to install\ne.g. http://svn.ali.as/cpan/releases/Config-Tiny-2.00.tar.gz"),
Wx::gettext('Install Local Distribution'),
'',
);
if ( $dialog->ShowModal == Wx::ID_CANCEL ) {
return;
}
my $string = $dialog->GetValue;
$dialog->Destroy;
unless ( defined $string and $string =~ /\S/ ) {
$main->error( Wx::gettext('Did not provide a distribution') );
return;
}
$class->install_cpanm( $main, $string );
}
sub install_cpanm {
my $class = shift;
my $main = shift;
my $module = shift;
# TODO cpanm might come with Padre but if we are dealing with another perl
# not the one that Padre runs on then we will need to look for cpanm
# in some other place
# Find 'cpanm', used to install modules
require Config;
my %seen = ();
my @where =
grep { defined $_ and length $_ and not $seen{$_}++ }
map { $Config::Config{$_} }
qw{
sitescriptexp
sitebinexp
vendorscriptexp
vendorbinexp
scriptdirexp
binexp
};
push @where, split /$Config::Config{path_sep}/, $ENV{PATH};
my $cpanm = '';
foreach my $dir (@where) {
my $path = File::Spec->catfile( $dir, 'cpanm' );
if ( -f $path ) {
$cpanm = $path;
last;
}
}
unless ($cpanm) {
$main->error( Wx::gettext('cpanm is unexpectedly not installed') );
return;
}
# Create the command
require Padre::Perl;
my $perl = Padre::Perl::cperl();
my $cmd = qq{"$perl" "$cpanm" "$module"};
$main->run_command($cmd);
return;
}
1;
# Copyright 2008-2013 The Padre development team as listed in Padre.pm.
# LICENSE
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl 5 itself.
|