Outthentic
view release on metacpan or search on metacpan
lib/Outthentic/Story.pm view on Meta::CPAN
get_prop( 'story_vars' )->{$name};
}
sub story_vars_pretty {
join " ", map { "$_:".(story_var($_)) } sort keys %{get_prop( 'story_vars' ) };
}
sub print_hook_header {
my $task_name = get_prop('task_name');
my $format = get_prop('format');
my $data;
if ($format eq 'production') {
$data = timestamp().' : '.($task_name || '').' '.'[hook]'
} elsif ($format ne 'concise') {
$data = timestamp().' : '.($task_name || '' ).' '.(nocolor() ? ' hook' : colored(['yellow'],'[hook]'))
}
note($data) if $format ne 'concise';
}
sub note {
my $message = shift;
my $no_new_line = shift;
binmode(STDOUT, ":utf8");
print $message;
print "\n" unless $no_new_line;
}
sub nocolor {
get_prop('nocolor')
}
sub timestamp {
sprintf '%02d-%02d-%02d %02d:%02d:%02d',
localtime->year()+1900,
localtime->mon()+1, localtime->mday,
localtime->hour, localtime->min, localtime->sec;
}
sub dump_os {
return $^O if $^O =~ 'MSWin';
my $cmd = <<'HERE';
#! /usr/bin/env sh
# Find out the target OS
if [ -s /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif lsb_release -h >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -s /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -s /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -s /etc/SuSe-release ]; then
# Older SuSE/etc.
printf "TODO\n"
elif [ -s /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
OS=$(cat /etc/redhat-release| head -n 1)
else
RELEASE_INFO=$(cat /etc/*-release 2>/dev/null | head -n 1)
if [ ! -z "$RELEASE_INFO" ]; then
OS=$(printf -- "$RELEASE_INFO" | awk '{ print $1 }')
VER=$(printf -- "$RELEASE_INFO" | awk '{ print $NF }')
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
fi
echo "$OS$VER"
HERE
`$cmd`
}
sub _resolve_os {
if (!$OS){
DONE: while (1) {
my $data = dump_os();
$data=~/alpine/i and $OS = 'alpine' and last DONE;
$data=~/minoca/i and $OS = "minoca" and last DONE;
$data=~/centos linux(\d+)/i and $OS = "centos$1" and last DONE;
$data=~/Red Hat.*release\s+(\d)/i and $OS = "centos$1" and last DONE;
$data=~/arch/i and $OS = 'archlinux' and last DONE;
$data=~/funtoo/i and $OS = 'funtoo' and last DONE;
$data=~/fedora/i and $OS = 'fedora' and last DONE;
$data=~/amazon/i and $OS = 'amazon' and last DONE;
$data=~/ubuntu/i and $OS = 'ubuntu' and last DONE;
$data=~/debian/i and $OS = 'debian' and last DONE;
( run in 3.190 seconds using v1.01-cache-2.11-cpan-d7f47b0818f )