#=============================================================================
# Doloforge::Command : base object for the doloforge command modules
#
# This object defines the interface all Doloforge::Command:: objects should
# conform to.
#
# Full help :
#   perldoc Doloforge::Command
#=============================================================================


package Doloforge::Command;

use strict;
use warnings;

use base qw(Doloforge::Base);

use POSIX;
#use English qw(-no_match_vars);
use Pod::Text;


#=============================================================================
=encoding utf8

=head1 NAME

Doloforge::Command - Base object for the doloforge command modules

=cut


#=============================================================================
# Class-method Factory
#
# Creates a new command object from a class name, giving it the general
# Doloforge configuration, and reading the class-specific config file.
# This class-method facilitates full instanciation : require + yaml + new

sub Factory {
    # Call the generic factory, simply asking for a specific base class
    return &Doloforge::Base::Factory('Doloforge::Command', @_);
}


#=============================================================================
# Method getOptions
#
# Accepted arguments from the command-line, in the form accepted by Getopt::Long.
# Options with no value that match method names of that package will be called as
# methods, with the decoded options as parameters.

sub getOptions {
    die "Pure virtual method called: Doloforge::Command::getOptions()\n";
}


#=============================================================================
# Method help
#
# Print out help message of the actual instance, defined by Pod::Text, which
# retreive the POD from the .pm file.

sub help {
    my $self = shift;

    # Get the class name of the current object (Doloforge::Command::something, not just Doloforge::Command)
    my $file = ref($self);  # $self is a reference to the instance, which is the class name in scalar context
    $file =~ s!::!/!g;      # convert '::' into '/'
    $file .= '.pm';         # add a final '.pm' to get a file name from the class name
    $file = $INC{$file};    # the %INC hash contains the path of each loaded package (cf. man perlvar)

    # Extract the POD from the file and print it to STDOUT ('-')
    my $parser = new Pod::Text();
    $parser->parse_from_file($file, '-');
    exit(2);
}



1;
__END__

=head1 AUTHOR

Nicolas Huillard <F<nicolas@huillard.net>>, Dolomède

=head1 SEE ALSO

doloforge(1)

=cut
