Move CPANPLUS from lib/ to ext/
[p5sagit/p5-mst-13.2.git] / ext / CPANPLUS / lib / CPANPLUS / Dist / Base.pm
CommitLineData
6aaee015 1package CPANPLUS::Dist::Base;
2
3use strict;
4
4443dd53 5use base qw[CPANPLUS::Dist];
6use vars qw[$VERSION];
7$VERSION = $CPANPLUS::Internals::VERSION = $CPANPLUS::Internals::VERSION;
8
6aaee015 9
10=head1 NAME
11
12CPANPLUS::Dist::Base - Base class for custom distribution classes
13
14=head1 SYNOPSIS
15
16 package CPANPLUS::Dist::MY_IMPLEMENTATION
17
18 use base 'CPANPLUS::Dist::Base';
19
20 sub prepare {
21 my $dist = shift;
22
23 ### do the 'standard' things
24 $dist->SUPER::prepare( @_ ) or return;
25
26 ### do MY_IMPLEMENTATION specific things
27 ...
28
29 ### don't forget to set the status!
30 return $dist->status->prepared( $SUCCESS ? 1 : 0 );
31 }
32
33
34=head1 DESCRIPTION
35
36CPANPLUS::Dist::Base functions as a base class for all custom
37distribution implementations. It does all the mundane work
38CPANPLUS would have done without a custom distribution, so you
39can override just the parts you need to make your own implementation
40work.
41
42=head1 FLOW
43
44Below is a brief outline when and in which order methods in this
45class are called:
46
47 $Class->format_available; # can we use this class on this system?
48
49 $dist->init; # set up custom accessors, etc
50 $dist->prepare; # find/write meta information
51 $dist->create; # write the distribution file
52 $dist->install; # install the distribution file
53
54 $dist->uninstall; # remove the distribution (OPTIONAL)
55
56=head1 METHODS
57
58=cut
59
4443dd53 60=head2 @subs = $Class->methods
61
62Returns a list of methods that this class implements that you can
63override.
64
65=cut
66
67sub methods {
68 return qw[format_available init prepare create install uninstall]
69}
6aaee015 70
71=head2 $bool = $Class->format_available
72
73This method is called when someone requests a module to be installed
74via the superclass. This gives you the opportunity to check if all
75the needed requirements to build and install this distribution have
76been met.
77
78For example, you might need a command line program, or a certain perl
79module installed to do your job. Now is the time to check.
80
81Simply return true if the request can proceed and false if it can not.
82
83The C<CPANPLUS::Dist::Base> implementation always returns true.
84
85=cut
86
87sub format_available { return 1 }
88
89
90=head2 $bool = $dist->init
91
92This method is called just after the new dist object is set up and
93before the C<prepare> method is called. This is the time to set up
94the object so it can be used with your class.
95
96For example, you might want to add extra accessors to the C<status>
97object, which you might do as follows:
98
99 $dist->status->mk_accessors( qw[my_implementation_accessor] );
100
101The C<status> object is implemented as an instance of the
4443dd53 102C<Object::Accessor> class. Please refer to its documentation for
6aaee015 103details.
104
105Return true if the initialization was successul, and false if it was
106not.
107
108The C<CPANPLUS::Dist::Base> implementation does not alter your object
109and always returns true.
110
111=cut
112
113sub init { return 1; }
114
115=head2 $bool = $dist->prepare
116
117This runs the preparation step of your distribution. This step is meant
118to set up the environment so the C<create> step can create the actual
119distribution(file).
120A C<prepare> call in the standard C<ExtUtils::MakeMaker> distribution
121would, for example, run C<perl Makefile.PL> to find the dependencies
122for a distribution. For a C<debian> distribution, this is where you
123would write all the metafiles required for the C<dpkg-*> tools.
124
125The C<CPANPLUS::Dist::Base> implementation simply calls the underlying
126distribution class (Typically C<CPANPLUS::Dist::MM> or
127C<CPANPLUS::Dist::Build>).
128
129Sets C<< $dist->status->prepared >> to the return value of this function.
130If you override this method, you should make sure to set this value.
131
132=cut
133
134sub prepare {
135 ### just in case you already did a create call for this module object
136 ### just via a different dist object
137 my $dist = shift;
138 my $self = $dist->parent;
139 my $dist_cpan = $self->status->dist_cpan;
140
141 my $cb = $self->parent;
142 my $conf = $cb->configure_object;
143
144 $dist->status->prepared( $dist_cpan->prepare( @_ ) );
145}
146
147=head2 $bool = $dist->create
148
149This runs the creation step of your distribution. This step is meant
150to follow up on the C<prepare> call, that set up your environment so
151the C<create> step can create the actual distribution(file).
152A C<create> call in the standard C<ExtUtils::MakeMaker> distribution
153would, for example, run C<make> and C<make test> to build and test
154a distribution. For a C<debian> distribution, this is where you
155would create the actual C<.deb> file using C<dpkg>.
156
157The C<CPANPLUS::Dist::Base> implementation simply calls the underlying
158distribution class (Typically C<CPANPLUS::Dist::MM> or
159C<CPANPLUS::Dist::Build>).
160
161Sets C<< $dist->status->dist >> to the location of the created
162distribution.
163If you override this method, you should make sure to set this value.
164
165Sets C<< $dist->status->created >> to the return value of this function.
166If you override this method, you should make sure to set this value.
167
168=cut
169
170sub create {
171 ### just in case you already did a create call for this module object
172 ### just via a different dist object
173 my $dist = shift;
174 my $self = $dist->parent;
175 my $dist_cpan = $self->status->dist_cpan;
176 $dist = $self->status->dist if $self->status->dist;
177 $self->status->dist( $dist ) unless $self->status->dist;
178
e3b7d412 179 my $cb = $self->parent;
180 my $conf = $cb->configure_object;
181 my $format = ref $dist;
6aaee015 182
183 ### make sure to set this variable, if the caller hasn't yet
184 ### just so we have some clue where the dist left off.
185 $dist->status->dist( $dist_cpan->status->distdir )
186 unless defined $dist->status->dist;
187
e3b7d412 188 $dist->status->created( $dist_cpan->create(prereq_format => $format, @_) );
6aaee015 189}
190
191=head2 $bool = $dist->install
192
193This runs the install step of your distribution. This step is meant
194to follow up on the C<create> call, which prepared a distribution(file)
195to install.
196A C<create> call in the standard C<ExtUtils::MakeMaker> distribution
197would, for example, run C<make install> to copy the distribution files
198to their final destination. For a C<debian> distribution, this is where
199you would run C<dpkg --install> on the created C<.deb> file.
200
201The C<CPANPLUS::Dist::Base> implementation simply calls the underlying
202distribution class (Typically C<CPANPLUS::Dist::MM> or
203C<CPANPLUS::Dist::Build>).
204
205Sets C<< $dist->status->installed >> to the return value of this function.
206If you override this method, you should make sure to set this value.
207
208=cut
209
210sub install {
211 ### just in case you already did a create call for this module object
212 ### just via a different dist object
213 my $dist = shift;
214 my $self = $dist->parent;
215 my $dist_cpan = $self->status->dist_cpan;
216
217 my $cb = $self->parent;
218 my $conf = $cb->configure_object;
219
220 $dist->status->installed( $dist_cpan->install( @_ ) );
221}
222
223=head2 $bool = $dist->uninstall
224
225This runs the uninstall step of your distribution. This step is meant
226to remove the distribution from the file system.
227A C<uninstall> call in the standard C<ExtUtils::MakeMaker> distribution
228would, for example, run C<make uninstall> to remove the distribution
229files the file system. For a C<debian> distribution, this is where you
230would run C<dpkg --uninstall PACKAGE>.
231
232The C<CPANPLUS::Dist::Base> implementation simply calls the underlying
233distribution class (Typically C<CPANPLUS::Dist::MM> or
234C<CPANPLUS::Dist::Build>).
235
236Sets C<< $dist->status->uninstalled >> to the return value of this function.
237If you override this method, you should make sure to set this value.
238
239=cut
240
241sub uninstall {
242 ### just in case you already did a create call for this module object
243 ### just via a different dist object
244 my $dist = shift;
245 my $self = $dist->parent;
246 my $dist_cpan = $self->status->dist_cpan;
247
248 my $cb = $self->parent;
249 my $conf = $cb->configure_object;
250
251 $dist->status->uninstalled( $dist_cpan->uninstall( @_ ) );
252}
253
2541;
255
256# Local variables:
257# c-indentation-style: bsd
258# c-basic-offset: 4
259# indent-tabs-mode: nil
260# End:
261# vim: expandtab shiftwidth=4: