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',
24 use POE
::Filter
::Line
;
29 # if ( not available in cooker ) is_in_dist
31 # compute dependencies find_prereqs
32 # repeat with each dep
34 # install local install_from_local
35 # while ( not available locally ) is_installed
37 # prompt user to fix manually
39 # import import_local_to_dist
40 # submit (included above)
41 # ack available (manual?)
44 # yes | urpmi perl(module::to::install) install_from_dist
48 # $ apt-file find Audio/MPD.pm
49 # libaudio-mpd-perl: /usr/share/perl5/Audio/MPD.pm
51 # - find dist hosting module
52 # - computing dependencies
53 # - installing dependencies
54 # - check cooker availability
57 # - check local availability
60 # - wait for kenobi build
70 my ($class, $module) = @_;
75 $short =~ s/[[:lower:]]//g;
76 my $obj = App
::CPAN2Pkg
::Module
->_new(
82 # spawning the session
83 my $session = POE
::Session
->create(
86 find_prereqs
=> \
&find_prereqs
,
88 _find_prereqs_end
=> \
&_find_prereqs_end
,
89 _find_prereqs_stderr
=> \
&_find_prereqs_stderr
,
90 _find_prereqs_stdout
=> \
&_find_prereqs_stdout
,
93 _stop
=> sub { warn "stop"; },
107 my ($k, $self) = @_[KERNEL
, HEAP
];
110 my $module = $self->name;
111 my $cmd = "cpanp /prereqs show $module";
113 $self->_log_new_step($k, 'Finding module prereqs',
114 "Running command: $cmd" );
117 my $wheel = POE
::Wheel
::Run
->new(
119 CloseEvent
=> '_find_prereqs_end',
120 StdoutEvent
=> '_find_prereqs_stdout',
121 StderrEvent
=> '_find_prereqs_stderr',
122 #ErrorEvent => '_find_prereqs_error',
123 StdoutFilter
=> POE
::Filter
::Line
->new,
124 StderrFilter
=> POE
::Filter
::Line
->new,
126 $wheel->shutdown_stdin;
127 $self->_wheels->{ $wheel->ID } = $wheel;
132 sub _find_prereqs_end
{
133 my ($k, $self, $id) = @_[KERNEL
, HEAP
, ARG0
];
135 my $wheel = delete $self->{_wheels
}->{$id};
138 split /\n/, $self->_output;
139 shift @lines; # remove the title line
141 map { (split /\s+/, $_)[0] }
144 $k->post('ui', 'append', $self, "prereq found: $_\n") for @prereqs;
147 sub _find_prereqs_stderr
{
148 my ($k, $self, $line) = @_[KERNEL
, HEAP
, ARG0
];
150 $k->post('ui', 'append', $self, $line);
153 sub _find_prereqs_stdout
{
154 my ($k, $self, $line) = @_[KERNEL
, HEAP
, ARG0
];
156 $self->_output( $self->_output . $line );
157 $k->post('ui', 'append', $self, $line);
161 # -- poe inline states
164 my ($k, $self) = @_[KERNEL
, HEAP
];
166 $k->alias_set($self);
167 $k->post('ui', 'new_module', $self);
168 $k->post('app', 'new_module', $self);
169 $k->yield('find_prereqs');
179 my ($self, $k, $step, $comment) = @_;
181 my $out = "\n\n" . '*' x
10 . "\n$step\n\n$comment\n\n";
182 $k->post('ui', 'append', $self, $out);
191 App::CPAN2Pkg::Module - poe session to drive a module packaging
197 C<App::CPAN2Pkg::Module> implements a POE session driving the whole
198 packaging process of a given module.
200 It is spawned by C<App::CPAN2Pkg> and implements the logic related to
201 the module availability in the distribution.
205 =head1 PUBLIC PACKAGE METHODS
207 =head2 my $id = App::CPAN2Pkg::Module->spawn( $module )
209 This method will create a POE session responsible for packaging &
210 installing the wanted C<$module>.
212 It will return the POE id of the session newly created.
216 =head1 PUBLIC EVENTS ACCEPTED
218 =head2 find_prereqs()
220 Start looking for any other module needed by current module.
226 This package is also a class, used B<internally> to store private data
227 needed for the packaging stuff. The following accessors are therefore
228 available, but should not be used directly:
232 =item name() - the module name
234 =item shortname() - the module shortname (only capital letters)
242 For all related information (bug reporting, source code repository,
243 etc.), refer to C<App::CPAN2Pkg>'s pod, section C<SEE ALSO>.
249 Jerome Quelin, C<< <jquelin@cpan.org> >>
253 =head1 COPYRIGHT & LICENSE
255 Copyright (c) 2009 Jerome Quelin, all rights reserved.
257 This program is free software; you can redistribute it and/or modify
258 it under the same terms as Perl itself.