#!/usr/bin/perl -w
#========================================================================
#
# dms
#
# DESCRIPTION
#
# Document::Manager and the script 'dms' implement the core of a
# document management system, allowing for files to be checked in and
# out, revision numbered, and assigned metadata such as ownership,
# title, or subject matter. The dms script provides a simple commandline
# implementation allowing for administrative or shell-script based
# access to the repository.  
#
# AUTHOR
#   Bryce W. Harrington <bryce at bryceharrington dot com>
#
# COPYRIGHT
#   Copyright (C) 2003 Bryce W. Harrington  
#   All Rights Reserved.
#
#   This module is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
#------------------------------------------------------------------------
#
# Last Modified:  $Date: 2004/08/14 17:35:33 $
#
# $Id: dms,v 1.2 2004/08/14 17:35:33 bryce Exp $
#
# $Log: dms,v $
# Revision 1.2  2004/08/14 17:35:33  bryce
# Changing distname from dms to Document-Manager.
# Creating preliminary dms script
#
#
#========================================================================

use strict;                             # Forces variable decl's
use Carp;                               # Improved error/warning prints
use Pod::Usage;                         # To report program usage
use Getopt::Long;                       # Basic cmdline arg handling
use Config::Simple;                     # Key=value config processor
use File::Basename;                     # fileparse(), basename(), dirname()
use File::Copy;                         # copy(), move()
use File::Find;                         # find(), finddepth()
use File::Path;                         # mkpath(), rmtree()
use File::Spec::Functions qw(:ALL);

#------------------------------------------------------------------------
# Global variables
#------------------------------------------------------------------------


use vars qw($VERSION $NAME);
$VERSION             = '1.00';
my $NAME             = 'dms';
my $HOME             = $ENV{ HOME } || '';
my %CONFIG           = ();
my $RC_USER          = $ENV{"\U\${NAME}"} || catdir(${HOME},'.'.${NAME});
my $RC_GLOBAL        = catdir('/etc',${NAME});

#------------------------------------------------------------------------
# Config file loading
#------------------------------------------------------------------------
if (-d $RC_GLOBAL) {
    load_resource(\%CONFIG, $RC_GLOBAL,   "conf");
}
if (-d $RC_USER) {
    load_resource(\%CONFIG, $RC_USER,     "conf");
}

#------------------------------------------------------------------------
# User config area
#------------------------------------------------------------------------


our $opt_version  = 0; # Prints the version and exits
our $opt_help     = 0; # Prints a brief help message
our $opt_helplong = 0; # Prints a long help message
our $opt_man      = 0; # Prints a manual page (detailed help)
our $opt_debug    = 0; # Prints debug messages
our $opt_user     = $ENV{'USER'};  # User name/id for accessing system (default $USER)

#------------------------------------------------------------------------
# Commandline option processing
#------------------------------------------------------------------------

Getopt::Long::Configure ("bundling");  
GetOptions(
           "version|V",   # Prints the version and exits
           "help|h",      # Prints a brief help message
           "helplong|H",  # Prints a long help message
           "man|",        # Prints a manual page (detailed help)
           "debug|D=i",   # Prints debug messages
           "user|u=s",    # User name/id for accessing system (default $USER)
            ) || pod2usage(1);

if ($opt_version) {
    print "$VERSION\n";
    exit 0;
}

pod2usage(-verbose => 0, -exitstatus => 0) if $opt_help;
pod2usage(-verbose => 1, -exitstatus => 0) if $opt_helplong;
pod2usage(-verbose => 2, -exitstatus => 0) if $opt_man;

#========================================================================
# Subroutines
#------------------------------------------------------------------------

#========================================================================
# Main program
#------------------------------------------------------------------------

print STDERR "Starting main program\n" if ($opt_debug>1);

# TODO: Main Algorithm

print STDERR "Ending main program\n\n" if ($opt_debug>1);

#########################################################################

__END__


=head1 NAME

dms - implements a document management systems' core engine

=head1 SYNOPSIS

dms [options] command filename [ filename [...] ]

 Options:
   -V, --version=boolean         Prints the version and exits
   -h, --help=boolean            Prints a brief help message
   -H, --helplong=boolean        Prints a long help message
       --man=boolean             Prints a manual page (detailed help)
   -D, --debug=integer           Prints debug messages
   -u, --user=string             User name/id for accessing system (default $USER)

=head1 DESCRIPTION

B<dms> - Document::Manager and the script 'dms' implement the core of a
document management system, allowing for files to be checked in and out,
revision numbered, and assigned metadata such as ownership, title, or
subject matter. The dms script provides a simple commandline
implementation allowing for administrative or shell-script based access
to the repository.

=head1 OPTIONS

=over 8

=item B<-V, --version>

Prints the version and exits

=item B<-h, --help>

Prints a brief help message

=item B<-H, --helplong>

Prints a long help message

=item B<--man>

Prints a manual page (detailed help)

=item B<-D, --debug>

Prints debug messages

=item B<-u, --user>

User name/id for accessing system (default $USER)


=back

See B<dms> -h for a summary of options.


=head1 PREREQUISITES

L<Carp>,
L<Pod::Usage>,
L<Getopt::Long>,
L<Config::Simple>,
L<File::Basename>,
L<File::Copy>,
L<File::Find>,
L<File::Path>,
L<File::Spec>


=head1 SCRIPT CATEGORIES

CPAN/Administrative

=head1 BUGS

None known.

=head1 VERSION

0.03

=head1 SEE ALSO

L<perl(1)>


=head1 AUTHOR

Bryce W. Harrington E<lt>bryce at bryceharrington dot comE<gt>

L<http://www.bryceharrington.com>

=head1 COPYRIGHT

Copyright (C) 2003 Bryce W. Harrington.
All Rights Reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 REVISION

Revision: $Revision: 1.2 $

=cut



