This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
77ad19b7763be4e12d03fc57ce1e6bc6fe785201
[perl5.git] / cpan / CPAN / lib / CPAN / Plugin.pm
1 package CPAN::Plugin;
2
3 use strict;
4 use warnings;
5
6 our $VERSION = '0.96';
7
8 require CPAN;
9
10 ######################################################################
11
12 sub 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 ######################################################################
32 sub plugin_requires {                    # ;
33 }
34
35 ######################################################################
36 sub distribution_object {                # ;
37     my ($self) = @_;
38     $self->{distribution_object};
39 }
40
41 ######################################################################
42 sub 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 ######################################################################
51 sub distribution_info {                  # ;
52     my ($self) = @_;
53
54     CPAN::DistnameInfo->new ($self->distribution->id);
55 }
56
57 ######################################################################
58 sub 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 ######################################################################
66 sub 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
83 package CPAN::Plugin;
84
85 1;
86
87 __END__
88
89 =pod
90
91 =head1 NAME
92
93 CPAN::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
110 The plugin system in the CPAN shell was introduced in version 2.07 and
111 is still considered experimental.
112
113 =head2 How Plugins work?
114
115 See L<CPAN/"Plugin support">.
116
117 =head1 METHODS
118
119 =head2 plugin_requires
120
121 returns list of packages given plugin requires for functionality.
122 This list is evaluated using C<CPAN->use_inst> method.
123
124 =head2 distribution_object
125
126 Get current distribution object.
127
128 =head2 distribution
129
130 =head2 distribution_info
131
132 =head2 build_dir
133
134 Simple delegatees for misc parameters derived from distribution
135
136 =head2 is_xs
137
138 Predicate to detect whether package contains XS.
139
140 =head1 AUTHOR
141
142 Branislav Zahradnik <barney@cpan.org>
143
144 =cut
145