summaryrefslogtreecommitdiff
path: root/lib/DhMakeELPA.pm
blob: b7a9b5e8a8330db39ad04956c52a57904a0fe64f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package DhMakeELPA;

use warnings;
use strict;

use base 'Class::Accessor';

__PACKAGE__->mk_accessors( qw( cfg ) );

use DhMakeELPA::Config;

=item run( I<%init> )

Runs DhMakeELPA.

Unless the %init contains an I<cfg> member, constructs and instance of
L<DhMakeELPA::Config> and assigns it to I<$init{cfg}>.

Then determines the dh-make-elpa command requested (via cfg->command),
loads the appropriate I<DhMakeELPA::Command::$command> class,
constructs an instance of it and calls its I<execute> method.

=cut

sub run {
    my ( $class, %c ) = @_;

    unless ( $c{cfg} ) {
        my $cfg = DhMakeELPA::Config->new;
        $cfg->parse_command_line_options;
        $c{cfg} = $cfg;
    }

    my $cmd_mod = $c{cfg}->command;
    $cmd_mod =~ s/-/_/g;
    require "DhMakeELPA/Command/$cmd_mod.pm";

    $cmd_mod =~ s{/}{::}g;
    $cmd_mod = "DhMakeELPA::Command::$cmd_mod";

    my $self = $cmd_mod->new( \%c );

    return $self->execute;
}

1;