« blib/lib/Amon2/Setup/Flavor/Large.pm
↑ Summary
blib/lib/auto/share/dist/Amon2/flavor/Basic/lib/__PATH__/Web/Plugin/Session.pm »
| 1 | package Amon2::Setup::VC::Git; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use utf8; | ||
| 5 | use File::Temp qw(tempfile); | ||
| 6 | |||
| 7 | sub new { | ||
| 8 | bless {}, $_[0]; | ||
| 9 | } | ||
| 10 | |||
| 11 | sub do_import { | ||
| 12 | my ($self) = @_; | ||
| 13 | |||
| 14 | unless ($self->_is_git_available('git')) { | ||
| 15 | warn "There is no git command.\n"; | ||
| 16 | return; | ||
| 17 | } | ||
| 18 | |||
| 19 | !system("git init") or die $?; | ||
| 20 | !system("git add .") or die $?; | ||
| 21 | !system(q{git commit -m "initial import"}) or die $?; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub _is_git_available { | ||
| 25 | my ($self) = @_; | ||
| 26 | |||
| 27 | if ($^O eq 'MSWin32') { | ||
| 28 | no warnings; | ||
| 29 | !system('git --version 2>&1 > NUL'); | ||
| 30 | } else { | ||
| 31 | my $pid = fork(); | ||
| 32 | die "Cannot fork: $!" if !defined $pid; | ||
| 33 | if ($pid) { # parent | ||
| 34 | waitpid($pid, 0); | ||
| 35 | require POSIX; | ||
| 36 | POSIX::WIFEXITED($?) && POSIX::WEXITSTATUS($?)==0 ? 1 : 0; | ||
| 37 | } else { # child | ||
| 38 | my ($logfh, $logfile) = tempfile(UNLINK => 1); | ||
| 39 | open STDOUT, '>', $logfile or die "$!"; | ||
| 40 | open STDERR, '>&STDOUT' or die "$!"; | ||
| 41 | no warnings; | ||
| 42 | exec('git', '--version'); | ||
| 43 | exit(9); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | 1; | ||
| 49 |