package Text::Wigwam::Loader;

    use strict;
    use warnings;
    our $VERSION = '0.01';

    sub fetch_package {
        my ($self, $cache, $Api, $finder, @files) = @_;
        local $_;
        $_ =~ s{::}{/}g for @files;
        return $self->fetch($cache, $Api, $finder, @files);
    }

    sub fetch {
         # Evaluates Perl libraries.
        no strict 'refs';
        my ($self, $cache, $Api, $finder, @files) = @_;
        my @loaded = ();
        die "Unable to load "
            . join( ', ' => @files )
            . " - no paths are defined for "
            . $finder->name
          unless $finder->get;
        foreach my $file ( @files ){
            next unless $file && length $file;
#            $file =~ s{::}{/}g;
            my $fname = $finder->file($file, qw/ .pm /)
              or die "Unable to locate $file in "
                     . $finder->name . " path " 
                     . join( ", " => $finder->get )
            ;
            my $rval = $cache->{$file} || require "$fname";
#                unless exists $INC{"$file.pm"};
            push( @loaded, $cache->{$file} = $rval );
        }
        return @loaded;
    }

1;
