#!/usr/bin/env perl

use strict;
use warnings;
use English;
use feature qw(say);

# act nice
use POSIX qw(nice);
nice 19;

my $WEB_ROOT='~/public_html';

print <<"INTRO";

Hi my name is $PROGRAM_NAME. 
I am usually run as a cron job to generate Perl 6 syntax highlighted htmls.

INTRO

my $status;

say "\n--Running 'git pull' for std";
$status = system('cd ..; git pull'); 
die "Could not git pull for std\n" if $status != 0;

say "\n--Running 'make clean all' for STD.pm";
$status = system('cd ..; make clean all'); 
die "Could not make STD.pm\n" if $status != 0;

say "\n-- Running syntax highlighter";
$status = system("cd ..; std_hilite/spec_highlight");
#die "Could not run spec_highlight\n" if $status != 0;

say "\n-- Copying the result to $WEB_ROOT/html";
$status = system("/bin/cp -R ../html $WEB_ROOT/"); 
die "Could not copy the output\n" if $status != 0;

say "\n-- I am done... Thanks for your valuable time";

=head1 sample usage in cron

PATH=/bin:/usr/bin:/usr/local/bin
LANG=en_US.UTF-8

# m h  dom mon dow   command
1 */5 * * *   (cd ~/std/std_hilite; ./cron_spec_highlight 2>&1 | tee html/log.txt)

=cut
