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
;
15 use App
::CPAN2Pkg
::Module
;
17 constructor
=> '_new',
19 _complete
=> '_complete',
20 _missing
=> '_missing',
26 our $VERSION = '0.3.0';
29 my ($class, $opts) = @_;
31 my $obj = App
::CPAN2Pkg
->_new(
37 my $session = POE
::Session
->create(
40 upstream_status
=> \
&upstream_status
,
41 install_status
=> \
&install_status
,
42 module_spawned
=> \
&module_spawned
,
45 upstream_install
=> \
&upstream_install
,
48 _stop
=> sub { warn "stop"; },
62 # if ( not available in cooker ) is_in_dist
64 # compute dependencies find_prereqs
65 # repeat with each dep
67 # install local install_from_local
68 # while ( not available locally ) is_installed
70 # prompt user to fix manually
72 # import import_local_to_dist
73 # submit (included above)
74 # ack available (manual?)
77 # urpmi --auto perl(module::to::install) install_from_dist
83 my ($k, $module, $is_installed) = @_[KERNEL
, ARG0
, ARG1
];
85 if ( not $is_installed ) {
86 $k->post($module, 'is_in_dist');
90 $k->post('ui', 'module_available', $module);
95 my ($k, $h, $module) = @_[KERNEL
, HEAP
, ARG0
];
96 my $name = $module->name;
97 $h->_module->{$name} = $module;
98 $k->post($module, 'is_installed');
102 my ($k, $h, $module) = @_[KERNEL
, HEAP
, ARG0
];
103 App
::CPAN2Pkg
::Module
->spawn($module);
107 my ($k, $h, $module, @prereqs) = @_[KERNEL
, HEAP
, ARG0
..$#_];
110 foreach my $m ( @prereqs ) {
111 # check if module is new. in which case, let's treat it.
112 $k->yield('package', $m) unless exists $h->_module->{$m};
114 # store missing module.
115 push @missing, $m unless exists $h->_complete->{$m};
118 $k->post('ui', 'prereqs', $module, @missing);
120 # module misses some prereqs - wait for them.
121 my $name = $module->name;
122 $h->_missing->{$name}{$_} = 1 for @missing;
123 $h->_prereq->{$_}{$name} = 1 for @missing;
126 # no prereqs, move on
127 $k->yield('prereqs_completed', $module);
132 sub upstream_install
{
133 my ($k, $module, $success) = @_[KERNEL
, ARG0
, ARG1
];
137 sub upstream_status
{
138 my ($k, $module, $is_available) = @_[KERNEL
, ARG0
, ARG1
];
139 my $event = $is_available ?
'install_from_dist' : 'find_prereqs';
140 $k->post($module, $event);
144 # -- poe inline states
147 my ($k, $opts) = @_[KERNEL
, ARG0
];
148 $k->alias_set('app');
150 # start packaging some modules
151 my $modules = $opts->{modules
};
152 $k->yield('package', $_) for @
$modules;
161 App::CPAN2Pkg - generating native linux packages from cpan
168 $ cpan2pkg Module::Foo Module::Bar ...
174 Don't use this module directly, refer to the C<cpan2pkg> script instead.
176 C<App::CPAN2Pkg> is the controller for the C<cpan2pkg> application. It
177 implements a POE session, responsible to schedule and advance module
180 It is spawned by the poe session responsible for the user interface.
184 =head1 PUBLIC PACKAGE METHODS
186 =head2 my $id = App::CPAN2Pkg->spawn( \%params )
188 This method will create a POE session responsible for coordinating the
191 It will return the POE id of the session newly created.
193 You can tune the session by passing some arguments as a hash
194 reference, where the hash keys are:
198 =item * modules => \@list_of_modules
200 A list of modules to start packaging.
207 =head1 PUBLIC EVENTS ACCEPTED
209 The following events are the module's API.
212 =head2 install_status( $module, $is_installed )
214 Sent when C<$module> knows whether it is installed locally (C<$is_installed>
218 =head2 module_spawned( $module )
220 Sent when C<$module> has been spawned successfully.
223 =head2 package( $module )
225 Request the application to package (if needed) the perl C<$module>. Note
226 that the module can be either the top-most module of a distribution or
227 deep inside said distribution.
230 =head2 prereqs( $module, @prereqs )
232 Inform main application that C<$module> needs some C<@prereqs> (possibly
236 =head2 upstream_install( $module, $success )
238 Sent after trying to install C<$module> from upstream dist. Result is passed
239 along with C<$success>.
242 =head2 upstream_status( $module, $is_available )
244 Sent when C<$module> knows whether it is available upstream (C<$is_available>
251 Please report any bugs or feature requests to C<app-cpan2pkg at
252 rt.cpan.org>, or through the web interface at
253 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-CPAN2Pkg>. I will
254 be notified, and then you'll automatically be notified of progress on
255 your bug as I make changes.
261 Our git repository is located at L<git://repo.or.cz/app-cpan2pkg.git>,
262 and can be browsed at L<http://repo.or.cz/w/app-cpan2pkg.git>.
265 You can also look for information on this module at:
269 =item * AnnoCPAN: Annotated CPAN documentation
271 L<http://annocpan.org/dist/App-CPAN2Pkg>
275 L<http://cpanratings.perl.org/d/App-CPAN2Pkg>
279 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-CPAN2Pkg>
287 Jerome Quelin, C<< <jquelin@cpan.org> >>
291 =head1 COPYRIGHT & LICENSE
293 Copyright (c) 2009 Jerome Quelin, all rights reserved.
295 This program is free software; you can redistribute it and/or modify
296 it under the same terms as Perl itself.