package Orchard::Session;

use strict;
use warnings;

use Exporter;
use JSON::XS;
use FileHandle;
use Data::Dumper;
use POSIX(qw/strftime/);
use Class::Load(qw/:all/);
use Capture::Tiny(qw/capture/);
use Getopt::Long::Descriptive(qw/describe_options/);


use lib '/Users/denk002/projects/collab/jgetter/perllib';
use Orchard::Logger(qw/logMessage/);

our @ISA       = qw(Exporter);
our @EXPORT    = qw/logMessage getdbx getdbh mysql_now clopt Dumper encode_json decode_json runcmd/;
our @EXPORT_OK = qw/logMessage getdbx getdbh mysql_now clopt Dumper encode_json decode_json runcmd/;

$Data::Dumper::Sortkeys = 1;

sub clopt {
    describe_options( '%c %o <some-arg>', @_ );
}

sub getdbx {
    my $host = shift;
    load_class('Orchard::DB::Schema');
    Orchard::DB::Schema->getdbx($host);
}

sub getdbh {
    my $conn = shift;
    my $host = shift;
    load_class('Orchard::DB::Connect');
    Orchard::DB::Connect->connect( $conn, $host );
}

sub mysql_now {
    strftime "%Y-%m-%d %H:%M:%S", localtime;
}

sub runcmd {
    my $command = shift;
    my $capture = [ capture { system($command) } ];
    $capture;
}

1;
