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
::Module
;
16 constructor
=> '_new',
19 shortname
=> 'shortname',
21 _prereqs
=> '_prereqs',
25 use POE
::Filter
::Line
;
30 # if ( not available in cooker ) is_in_dist
32 # compute dependencies find_prereqs
33 # repeat with each dep
35 # install local install_from_local
36 # while ( not available locally ) is_installed
38 # prompt user to fix manually
40 # import import_local_to_dist
41 # submit (included above)
42 # ack available (manual?)
45 # urpmi --auto perl(module::to::install) install_from_dist
49 # $ apt-file find Audio/MPD.pm
50 # libaudio-mpd-perl: /usr/share/perl5/Audio/MPD.pm
52 # - find dist hosting module
53 # - computing dependencies
54 # - installing dependencies
55 # - check cooker availability
58 # - check local availability
61 # - wait for kenobi build
71 my ($class, $module) = @_;
76 $short =~ s/[[:lower:]]//g;
77 my $obj = App
::CPAN2Pkg
::Module
->_new(
84 # spawning the session
85 my $session = POE
::Session
->create(
88 find_prereqs
=> \
&find_prereqs
,
89 is_in_dist
=> \
&is_in_dist
,
91 _find_prereqs
=> \
&_find_prereqs
,
96 _stop
=> sub { warn "stop"; },
110 my ($k, $self) = @_[KERNEL
, HEAP
];
113 my $module = $self->name;
114 my $cmd = "cpanp /prereqs show $module";
115 $self->_log_new_step($k, 'Finding module prereqs',
116 "Running command: $cmd" );
121 my $wheel = POE
::Wheel
::Run
->new(
123 CloseEvent
=> '_find_prereqs',
124 StdoutEvent
=> '_stdout',
125 StderrEvent
=> '_stderr',
126 StdoutFilter
=> POE
::Filter
::Line
->new,
127 StderrFilter
=> POE
::Filter
::Line
->new,
130 # need to store the wheel, otherwise the process goes woo!
131 $self->_wheels->{ $wheel->ID } = $wheel;
135 my ($k, $self) = @_[KERNEL
, HEAP
];
138 my $name = $self->name;
139 my $cmd = "urpmq --whatprovides 'perl($name)'";
140 $self->_log_new_step($k, 'Checking if packaged upstream',
141 "Running command: $cmd" );
146 my $wheel = POE
::Wheel
::Run
->new(
148 CloseEvent
=> '_is_in_dist',
149 StdoutEvent
=> '_stdout',
150 StderrEvent
=> '_stderr',
151 Conduit
=> 'pty-pipe', # urpmq wants a pty
152 StdoutFilter
=> POE
::Filter
::Line
->new,
153 StderrFilter
=> POE
::Filter
::Line
->new,
156 # need to store the wheel, otherwise the process goes woo!
157 $self->_wheels->{ $wheel->ID } = $wheel;
163 my ($k, $self, $id) = @_[KERNEL
, HEAP
, ARG0
];
166 my $wheel = delete $self->{_wheels
}->{$id};
171 split /\n/, $self->_output;
172 shift @lines; # remove the title line
174 map { (split /\s+/, $_)[0] }
178 foreach my $prereq ( @prereqs ) {
179 $k->post('ui', 'append', $self, "prereq found: $prereq\n");
180 $self->_prereqs->{$prereq} = 1;
183 $k->post('app', 'prereqs', $self, @prereqs);
187 my ($k, $self, $line) = @_[KERNEL
, HEAP
, ARG0
];
188 $k->post('ui', 'append', $self, "$line\n");
192 my ($k, $self, $line) = @_[KERNEL
, HEAP
, ARG0
];
194 $self->_output( $self->_output . $line );
195 $k->post('ui', 'append', $self, $line);
199 # -- poe inline states
202 my ($k, $self) = @_[KERNEL
, HEAP
];
204 $k->alias_set($self);
205 $k->post('ui', 'new_module', $self);
206 $k->post('app', 'new_module', $self);
207 $k->yield('is_in_dist');
217 my ($self, $k, $step, $comment) = @_;
219 my $out = "\n\n" . '*' x
10 . "\n$step\n\n$comment\n\n";
220 $k->post('ui', 'append', $self, $out);
229 App::CPAN2Pkg::Module - poe session to drive a module packaging
235 C<App::CPAN2Pkg::Module> implements a POE session driving the whole
236 packaging process of a given module.
238 It is spawned by C<App::CPAN2Pkg> and implements the logic related to
239 the module availability in the distribution.
243 =head1 PUBLIC PACKAGE METHODS
245 =head2 my $id = App::CPAN2Pkg::Module->spawn( $module )
247 This method will create a POE session responsible for packaging &
248 installing the wanted C<$module>.
250 It will return the POE id of the session newly created.
254 =head1 PUBLIC EVENTS ACCEPTED
256 =head2 find_prereqs()
258 Start looking for any other module needed by current module.
263 Check whether the package is provided by an existing upstream package.
268 This package is also a class, used B<internally> to store private data
269 needed for the packaging stuff. The following accessors are therefore
270 available, but should not be used directly:
274 =item name() - the module name
276 =item shortname() - the module shortname (only capital letters)
284 For all related information (bug reporting, source code repository,
285 etc.), refer to C<App::CPAN2Pkg>'s pod, section C<SEE ALSO>.
291 Jerome Quelin, C<< <jquelin@cpan.org> >>
295 =head1 COPYRIGHT & LICENSE
297 Copyright (c) 2009 Jerome Quelin, all rights reserved.
299 This program is free software; you can redistribute it and/or modify
300 it under the same terms as Perl itself.