1package CPAN::Plugin;
2
3use strict;
4use warnings;
5
6our $VERSION = '0.97';
7
8require CPAN;
9
10######################################################################
11
12sub new {                                # ;
13    my ($class, %params) = @_;
14
15    my $self = +{
16        (ref $class ? (%$class) : ()),
17        %params,
18    };
19
20    $self = bless $self, ref $class ? ref $class : $class;
21
22    unless (ref $class) {
23        local $_;
24        no warnings 'once';
25        $CPAN::META->use_inst ($_) for $self->plugin_requires;
26    }
27
28    $self;
29}
30
31######################################################################
32sub plugin_requires {                    # ;
33}
34
35######################################################################
36sub distribution_object {                # ;
37    my ($self) = @_;
38    $self->{distribution_object};
39}
40
41######################################################################
42sub distribution {                       # ;
43    my ($self) = @_;
44
45    my $distribution = $self->distribution_object->id;
46    CPAN::Shell->expand("Distribution",$distribution)
47      or $self->frontend->mydie("Unknowns distribution '$distribution'\n");
48}
49
50######################################################################
51sub distribution_info {                  # ;
52    my ($self) = @_;
53
54    CPAN::DistnameInfo->new ($self->distribution->id);
55}
56
57######################################################################
58sub build_dir {                          # ;
59    my ($self) = @_;
60
61    my $build_dir = $self->distribution->{build_dir}
62      or $self->frontend->mydie("Distribution has not been built yet, cannot proceed");
63}
64
65######################################################################
66sub is_xs {                              #
67    my ($self) = @_;
68
69    my @xs = glob File::Spec->catfile ($self->build_dir, '*.xs'); # quick try
70
71    unless (@xs) {
72        require ExtUtils::Manifest;
73        my $manifest_file = File::Spec->catfile ($self->build_dir, "MANIFEST");
74        my $manifest = ExtUtils::Manifest::maniread($manifest_file);
75        @xs = grep /\.xs$/, keys %$manifest;
76    }
77
78    scalar @xs;
79}
80
81######################################################################
82
83package CPAN::Plugin;
84
851;
86
87__END__
88
89=pod
90
91=head1 NAME
92
93CPAN::Plugin - Base class for CPAN shell extensions
94
95=head1 SYNOPSIS
96
97   package CPAN::Plugin::Flurb;
98   use parent 'CPAN::Plugin';
99
100   sub post_test {
101     my ($self, $distribution_object) = @_;
102     $self = $self->new (distribution_object => $distribution_object);
103     ...;
104   }
105
106=head1 DESCRIPTION
107
108=head2 Alpha Status
109
110The plugin system in the CPAN shell was introduced in version 2.07 and
111is still considered experimental.
112
113=head2 How Plugins work?
114
115See L<CPAN/"Plugin support">.
116
117=head1 METHODS
118
119=head2 plugin_requires
120
121returns list of packages given plugin requires for functionality.
122This list is evaluated using C<< CPAN->use_inst >> method.
123
124=head2 distribution_object
125
126Get current distribution object.
127
128=head2 distribution
129
130=head2 distribution_info
131
132=head2 build_dir
133
134Simple delegatees for misc parameters derived from distribution
135
136=head2 is_xs
137
138Predicate to detect whether package contains XS.
139
140=head1 AUTHOR
141
142Branislav Zahradnik <barney@cpan.org>
143
144=cut
145
146