package Plus;
our $VERSION   = '0.40';
use strict;
use warnings;
use Cwd;
use Data::Dumper;
use File::Spec;
use Carp;
use File::Basename;

my $PGM = basename($::0);

sub err_msg
{
    my $fmt = shift || '';
    @_ ? sprintf("$PGM: $fmt",@_) : $fmt;
}

sub readdir_plus
{
    my $d = shift || cwd;
    my $long;
    while (@_) {
        my ($x,$y) = (shift,shift);
        $long = $y if ('long' eq ($x || ''));
    }
    local (*DH);
    $d = File::Spec->rel2abs( $d );
    opendir(DH,$d) or croak err_msg("Could not open directory '$d'");
    my @a = grep { ! /^.{1,2}$/ } readdir DH;
    closedir DH;
    @a = map { File::Spec->catfile($d,$_) } @a if $long;
	return @a;
}



sub mkdir_plus
{
    my ($d,$m) = @_;
    $d ||= cwd;
    $d = File::Spec->rel2abs( $d );
    return if -d $d;
    return if mkdir($d,$m);
    $d =~ s/\/$//;
    my ($vol,$dir) = File::Spec->splitpath( $d, 'nofile' );
    my @a = File::Spec->splitdir($dir);
    my @b;
    my $fail;
    while (! $fail && @a) {
        my $dx = File::Spec->catdir(@b) || '';
        $dx = File::Spec->catpath($vol,$dx);
        $fail = 1 if (!-d $dx && !mkdir($dx,$m));
        push @b, (shift @a);
    }
    return if !$fail;
    # One last desparate attempt
    `mkdir -p $d 2>/dev/null`;
    return if -d $d;
    croak err_msg("Could not create directory '$d'");
}


sub exclude_undef
{
    my @a;
    map { push(@a,$_) if defined $_ } @_;
    return @a;
}


sub init_with_word_array
{
    my %h;
    map { $h{$_} = 1 } @_;
    return ( %h, );
}



sub plus_modulino_test
{
    use Pod::HtmlEasy;
    my $podhtml = Pod::HtmlEasy->new() ;
    my $html = $podhtml->pod2html( $0, __PACKAGE__ . '.html', title => "Plus",) ;
    print "$html\n" ;
}

plus_modulino_test() if !caller;


1;






__END__

=head1 NAME

Plus: Some nice functions.

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 Parameters

=over 4

=item xxx

=item yyy

=over 4

blah blah 

=back

=item xxxx

=back

=head1 METHODS

=over 2

=item foo

=item bar

=back

=head1 EXAMPLES 




=head1 CAVEATS



=head1 AUTHOR

 Jim E Quinlan  
 perl -e "print join('', reverse qw/g r o . n a p c @ n a l n i u q j/ )"

=back

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2006 James E. Quinlan  All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

See http://www.perl.com/language/misc/Artistic.html" and http://www.gnu.org/copyleft/gpl.html.

=head1 SEE ALSO



=cut
