package WIT::Utils;

# WIT - unsorted useful subroutines
# Copyright (C) 2009 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License

use strict;
use warnings;

our (@ISA, @EXPORT);

BEGIN {
        require Exporter;

        @ISA    = qw(Exporter);
        @EXPORT = qw(mesg warn fail heredoc);
}

sub mesg
{
        print "@_\n";
}

sub warn
{
        print STDERR "* Warning: @_\n";
}

sub fail
{
        print STDERR "Error: @_\n";
        exit 1;
}

sub heredoc
{
        my $txt = shift || return;
        my $num = shift || 1;

        return $txt unless $num;

        $txt =~ s/^\s+//ms;
        $txt =~ s/^\t{$num}//msg;
        return $txt;
}

1;
