| 1 | # | ||
| 2 | # This file is part of App-CPAN2Pkg | ||
| 3 | # | ||
| 4 | # This software is copyright (c) 2009 by Jerome Quelin. | ||
| 5 | # | ||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||
| 8 | # | ||
| 9 | use 5.012; | ||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | |||
| 13 | package App::CPAN2Pkg; | ||
| 14 | # ABSTRACT: generating native linux packages from cpan | ||
| 15 | $App::CPAN2Pkg::VERSION = '3.004'; | ||
| 16 | use MooseX::Singleton; | ||
| 17 | use MooseX::Has::Sugar; | ||
| 18 | use POE; | ||
| 19 | use Readonly; | ||
| 20 | |||
| 21 | use App::CPAN2Pkg::Controller; | ||
| 22 | use App::CPAN2Pkg::UI::Text; | ||
| 23 | use App::CPAN2Pkg::UI::Tk; | ||
| 24 | use App::CPAN2Pkg::Utils qw{ $LINUX_FLAVOUR $WORKER_TYPE }; | ||
| 25 | |||
| 26 | # -- private attributes | ||
| 27 | |||
| 28 | # keep track of modules being processed. | ||
| 29 | has _modules => ( | ||
| 30 | ro, | ||
| 31 | isa => 'HashRef[App::CPAN2Pkg::Module]', | ||
| 32 | traits => ['Hash'], | ||
| 33 | handles => { | ||
| 34 | all_modules => 'keys', | ||
| 35 | seen_module => 'exists', | ||
| 36 | register_module => 'set', | ||
| 37 | forget_module => 'delete', | ||
| 38 | module => 'get', | ||
| 39 | nb_modules => 'count', | ||
| 40 | } | ||
| 41 | ); | ||
| 42 | |||
| 43 | |||
| 44 | # -- public methods | ||
| 45 | |||
| 46 | |||
| 47 | # those methods above are provided by moose traits for free | ||
| 48 | |||
| 49 | |||
| 50 | |||
| 51 | sub run { | ||
| 52 | my (undef, $opt, @modules) = @_; | ||
| 53 | |||
| 54 | # check if the platform is supported | ||
| 55 | eval "require $WORKER_TYPE"; | ||
| 56 | die "Platform $LINUX_FLAVOUR is not supported" if $@ =~ /^Can't locate/; | ||
| 57 | die $@ if $@; | ||
| 58 | |||
| 59 | # create the poe sessions | ||
| 60 | App::CPAN2Pkg::Controller->new( queue=>\@modules ); | ||
| 61 | my $ui = $opt->{ui} eq "gui" | ||
| 62 | ? "App::CPAN2Pkg::UI::Tk" : "App::CPAN2Pkg::UI::Text"; | ||
| 63 | $ui->new; | ||
| 64 | |||
| 65 | # and let's start the fun! | ||
| 66 | POE::Kernel->run; | ||
| 67 | } | ||
| 68 | |||
| 69 | no Moose; | ||
| 70 | __PACKAGE__->meta->make_immutable; | ||
| 71 | |||
| 72 | 1; | ||
| 73 | |||
| 74 | __END__ |