
package Text::Wigwam::Paths::Class;

    use strict;
    use warnings;
    use File::Spec::Functions qw(catfile);

    our $VERSION = '0.01';

    sub new {
        my( $class, $name, @args ) = @_;
        return bless {
            name => $name,
            paths => [ @args ],
            pre => [ ],
        }, ref($class) || $class;
    }

    sub file {
        my( $self, $file, @suffixes ) = @_;
        my @files = ();
        my $dir;
        for my $suffix ( '', @suffixes ) {
            for $dir ( $self->get ) {
                push(
                    @files,
                    catfile(
                        $dir,
                        $file.$suffix
                    )
                )
            }
        }
        for my $full ( @files ){
            return $full if( -f $full && -r $full );
        }
        return undef;
    }

    sub folder {
        my( $self, $folder ) = @_;
        for my $dir ( $self->get ){
            my $full = catfile( $dir, $folder );
            return $full if( -d $full && -r $full );
        }
        return undef;
    }

    sub name { return $_[0]->{name} }

    sub get {
        my ($self) = @_;
        return( @{$self->{pre}}, @{$self->{paths}} )
    }

    sub add {
        my( $self, @args ) = @_;
         # Remove trailing slashes
        $_ =~ s/\/$// for (@args);
        push( @{$self->{paths}}, @args ) if @args;
        return $self->get;
#        return @{$self->{paths}};
    }

    sub set {
        my( $self, @args ) = @_;
        $_ =~ s/\/$// for (@{$self->{paths}} = @args);
        return $self->get;
#        return @{$self->{paths}};
    }

    sub pre {
        my( $self, @args ) = @_;
        $_ =~ s/\/$// for (@{$self->{pre}} = @args);
        return @{$self->{pre}};
    }

1;

__END__

=head1 Usage

This module was designed to manage a single list of arbitrary directory
paths. It is not intended to be used directly, but through its parent
module Text::Wigwam::Paths.

 my $Path = Text::Wigwam::Paths::Class->new qw( class_name );

The path list can then be manipulated via a few simple methods.

The set method replaces any pre-existing list with a new list and then
returns the new list.

 $Path->set( @pathlist );

The add method appends new list items to the end of any pre-existing
list items, then returns the new list.

 my @path2 = $Path->add( '/path/to/alt/files' );

The get method simply returns the specified list.

 my @path3 = $Path->get;

