module_*available() replaced by upstream_status()
[app-cpan2pkg.git] / lib / App / CPAN2Pkg.pm
blob9f90809de05d7ccb94abf07d0cf9ec5afacc13f1
2 # This file is part of App::CPAN2Pkg.
3 # Copyright (c) 2009 Jerome Quelin, all rights reserved.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the same terms as Perl itself.
10 package App::CPAN2Pkg;
12 use strict;
13 use warnings;
15 use App::CPAN2Pkg::Module;
16 use POE;
18 our $VERSION = '0.2.0';
20 sub spawn {
21 my ($class, $opts) = @_;
23 my $session = POE::Session->create(
24 inline_states => {
25 # public events
26 upstream_status => \&upstream_status,
27 install_status => \&install_status,
28 module_spawned => \&module_spawned,
29 package => \&package,
30 # poe inline states
31 _start => \&_start,
32 _stop => sub { warn "stop"; },
34 args => $opts,
36 return $session->ID;
41 #--
42 # SUBS
45 # if ( not available in cooker ) is_in_dist
46 # then
47 # compute dependencies find_prereqs
48 # repeat with each dep
49 # cpan2dist cpan2dist
50 # install local install_from_local
51 # while ( not available locally ) is_installed
52 # do
53 # prompt user to fix manually
54 # done
55 # import import_local_to_dist
56 # submit (included above)
57 # ack available (manual?)
59 # else
60 # urpmi --auto perl(module::to::install) install_from_dist
61 # fi
63 # -- public events
65 sub upstream_status {
66 my ($k, $module, $is_available) = @_[KERNEL, ARG0, ARG1];
67 my $event = $is_available ? 'install_from_dist' : 'find_prereqs';
68 $k->post($module, $event);
71 sub install_status {
72 my ($k, $module, $installed) = @_[KERNEL, ARG0, ARG1];
74 if ( not $installed ) {
75 $k->post($module, 'is_in_dist');
76 return;
79 # update prereqs
82 sub module_spawned {
83 my ($k, $module) = @_[KERNEL, ARG0];
84 $k->post($module, 'is_installed');
87 sub package {
88 my ($k, $module) = @_[KERNEL, ARG0];
89 App::CPAN2Pkg::Module->spawn($module);
93 # -- poe inline states
95 sub _start {
96 my ($k, $opts) = @_[KERNEL, ARG0];
97 $k->alias_set('app');
99 # start packaging some modules
100 my $modules = $opts->{modules};
101 $k->yield('package', $_) for @$modules;
106 __END__
108 =head1 NAME
110 App::CPAN2Pkg - generating native linux packages from cpan
114 =head1 SYNOPSIS
116 $ cpan2pkg
117 $ cpan2pkg Module::Foo Module::Bar ...
121 =head1 DESCRIPTION
123 Don't use this module directly, refer to the C<cpan2pkg> script instead.
125 C<App::CPAN2Pkg> is the controller for the C<cpan2pkg> application. It
126 implements a POE session, responsible to schedule and advance module
127 packagement.
129 It is spawned by the poe session responsible for the user interface.
133 =head1 PUBLIC PACKAGE METHODS
135 =head2 my $id = App::CPAN2Pkg->spawn( \%params )
137 This method will create a POE session responsible for coordinating the
138 package(s) creation.
140 It will return the POE id of the session newly created.
142 You can tune the session by passing some arguments as a hash
143 reference, where the hash keys are:
145 =over 4
147 =item * modules => \@list_of_modules
149 A list of modules to start packaging.
152 =back
156 =head1 PUBLIC EVENTS ACCEPTED
158 The following events are the module's API.
161 =head2 install_status( $module, $is_installed )
163 Sent when C<$module> knows whether it is installed locally (C<$is_installed>
164 set to true) or not.
167 =head2 module_spawned( $module )
169 Sent when C<$module> has been spawned successfully.
172 =head2 package( $module )
174 Request the application to package (if needed) the perl C<$module>. Note
175 that the module can be either the top-most module of a distribution or
176 deep inside said distribution.
179 =head2 upstream_status( $module, $is_available )
181 Sent when C<$module> knows whether it is available upstream (C<$is_available>
182 set to true) or not.
186 =head1 BUGS
188 Please report any bugs or feature requests to C<app-cpan2pkg at
189 rt.cpan.org>, or through the web interface at
190 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-CPAN2Pkg>. I will
191 be notified, and then you'll automatically be notified of progress on
192 your bug as I make changes.
196 =head1 SEE ALSO
198 Our git repository is located at L<git://repo.or.cz/app-cpan2pkg.git>,
199 and can be browsed at L<http://repo.or.cz/w/app-cpan2pkg.git>.
202 You can also look for information on this module at:
204 =over 4
206 =item * AnnoCPAN: Annotated CPAN documentation
208 L<http://annocpan.org/dist/App-CPAN2Pkg>
210 =item * CPAN Ratings
212 L<http://cpanratings.perl.org/d/App-CPAN2Pkg>
214 =item * Open bugs
216 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-CPAN2Pkg>
218 =back
222 =head1 AUTHOR
224 Jerome Quelin, C<< <jquelin@cpan.org> >>
228 =head1 COPYRIGHT & LICENSE
230 Copyright (c) 2009 Jerome Quelin, all rights reserved.
232 This program is free software; you can redistribute it and/or modify
233 it under the same terms as Perl itself.
235 =cut