| 1 | package Enbld::Module::Perl; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use parent qw/Enbld::Module/; | ||
| 7 | |||
| 8 | use FindBin qw/$Bin/; | ||
| 9 | |||
| 10 | use File::Spec; | ||
| 11 | |||
| 12 | require Enbld::Home; | ||
| 13 | require Enbld::Feature; | ||
| 14 | require Enbld::Error; | ||
| 15 | |||
| 16 | sub initialize { | ||
| 17 | my $self = shift; | ||
| 18 | |||
| 19 | # install cpanm | ||
| 20 | my $cpan = File::Spec->catfile( $self->{path}, 'bin', 'cpan' ); | ||
| 21 | $self->{installer} = File::Spec->catfile( $self->{path}, 'bin', 'cpanm' ); | ||
| 22 | |||
| 23 | require Enbld::Logger; | ||
| 24 | my $logfile = Enbld::Logger->logfile; | ||
| 25 | |||
| 26 | system( "$cpan App::cpanminus >> $logfile 2>&1" ); | ||
| 27 | |||
| 28 | if ( $? >> 8 ) { | ||
| 29 | Enbld::Error->throw( "Can't install cpanm" ); | ||
| 30 | } | ||
| 31 | |||
| 32 | # fullpath | ||
| 33 | my $path; | ||
| 34 | if ( File::Spec->file_name_is_absolute( $self->{module_file} ) ) { | ||
| 35 | $path = $self->{module_file}; | ||
| 36 | } else { | ||
| 37 | $path = File::Spec->catfile( $Bin, $self->{module_file} ); | ||
| 38 | } | ||
| 39 | |||
| 40 | if ( ! -e $path ) { | ||
| 41 | Enbld::Error->throw( "Can't find cpanfile:$path" ); | ||
| 42 | } | ||
| 43 | |||
| 44 | $self->{module_file_fullpath} = $path; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub install_command { | ||
| 48 | my $self = shift; | ||
| 49 | |||
| 50 | my $cmd = $self->{installer} . ' --cpanfile !file! --installdeps .'; | ||
| 51 | $cmd =~ s/!file!/$self->{module_file_fullpath}/; | ||
| 52 | |||
| 53 | return $cmd; | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; |