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
,
90 _find_prereqs_end
=> \
&_find_prereqs_end
,
91 _find_prereqs_stderr
=> \
&_append
,
92 _find_prereqs_stdout
=> \
&_stdout
,
95 _stop
=> sub { warn "stop"; },
109 my ($k, $self) = @_[KERNEL
, HEAP
];
112 my $module = $self->name;
113 my $cmd = "cpanp /prereqs show $module";
115 $self->_log_new_step($k, 'Finding module prereqs',
116 "Running command: $cmd" );
119 my $wheel = POE
::Wheel
::Run
->new(
121 CloseEvent
=> '_find_prereqs_end',
122 StdoutEvent
=> '_find_prereqs_stdout',
123 StderrEvent
=> '_find_prereqs_stderr',
124 #ErrorEvent => '_find_prereqs_error',
125 StdoutFilter
=> POE
::Filter
::Line
->new,
126 StderrFilter
=> POE
::Filter
::Line
->new,
128 $wheel->shutdown_stdin;
129 $self->_wheels->{ $wheel->ID } = $wheel;
134 sub _find_prereqs_end
{
135 my ($k, $self, $id) = @_[KERNEL
, HEAP
, ARG0
];
138 my $wheel = delete $self->{_wheels
}->{$id};
143 split /\n/, $self->_output;
144 shift @lines; # remove the title line
146 map { (split /\s+/, $_)[0] }
150 foreach my $prereq ( @prereqs ) {
151 $k->post('ui', 'append', $self, "prereq found: $prereq\n");
152 $self->_prereqs->{$prereq} = 1;
155 $k->post('app', 'prereqs', $self, @prereqs);
159 my ($k, $self, $line) = @_[KERNEL
, HEAP
, ARG0
];
160 $k->post('ui', 'append', $self, "$line\n");
164 my ($k, $self, $line) = @_[KERNEL
, HEAP
, ARG0
];
166 $self->_output( $self->_output . $line );
167 $k->post('ui', 'append', $self, $line);
171 # -- poe inline states
174 my ($k, $self) = @_[KERNEL
, HEAP
];
176 $k->alias_set($self);
177 $k->post('ui', 'new_module', $self);
178 $k->post('app', 'new_module', $self);
179 $k->yield('find_prereqs');
189 my ($self, $k, $step, $comment) = @_;
191 my $out = "\n\n" . '*' x
10 . "\n$step\n\n$comment\n\n";
192 $k->post('ui', 'append', $self, $out);
201 App::CPAN2Pkg::Module - poe session to drive a module packaging
207 C<App::CPAN2Pkg::Module> implements a POE session driving the whole
208 packaging process of a given module.
210 It is spawned by C<App::CPAN2Pkg> and implements the logic related to
211 the module availability in the distribution.
215 =head1 PUBLIC PACKAGE METHODS
217 =head2 my $id = App::CPAN2Pkg::Module->spawn( $module )
219 This method will create a POE session responsible for packaging &
220 installing the wanted C<$module>.
222 It will return the POE id of the session newly created.
226 =head1 PUBLIC EVENTS ACCEPTED
228 =head2 find_prereqs()
230 Start looking for any other module needed by current module.
236 This package is also a class, used B<internally> to store private data
237 needed for the packaging stuff. The following accessors are therefore
238 available, but should not be used directly:
242 =item name() - the module name
244 =item shortname() - the module shortname (only capital letters)
252 For all related information (bug reporting, source code repository,
253 etc.), refer to C<App::CPAN2Pkg>'s pod, section C<SEE ALSO>.
259 Jerome Quelin, C<< <jquelin@cpan.org> >>
263 =head1 COPYRIGHT & LICENSE
265 Copyright (c) 2009 Jerome Quelin, all rights reserved.
267 This program is free software; you can redistribute it and/or modify
268 it under the same terms as Perl itself.