Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mention that files are cached
  • Loading branch information
kraih committed Feb 19, 2014
1 parent 818d5a7 commit 9e8228e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/Mojo/Loader.pm
Expand Up @@ -31,27 +31,27 @@ sub load {
sub search {
my ($self, $ns) = @_;

my (@modules, %found);
my %modules;
for my $directory (@INC) {
next unless -d (my $path = catdir $directory, split(/::|'/, $ns));

# List "*.pm" files in directory
opendir(my $dir, $path);
for my $file (grep /\.pm$/, readdir $dir) {
next if -d catfile splitdir($path), $file;
my $class = "${ns}::" . fileparse $file, qr/\.pm/;
push @modules, $class unless $found{$class}++;
$modules{"${ns}::" . fileparse $file, qr/\.pm/}++;
}
}

return \@modules;
return [keys %modules];
}

sub _all {
my $class = shift;

return $CACHE{$class} if $CACHE{$class};
my $handle = do { no strict 'refs'; \*{"${class}::DATA"} };
return $CACHE{$class} || {} if $CACHE{$class} || !fileno $handle;
return {} unless fileno $handle;
seek $handle, 0, 0;
my $data = join '', <$handle>;

Expand Down Expand Up @@ -113,7 +113,8 @@ following new ones.
my $all = $loader->data('Foo::Bar');
my $index = $loader->data('Foo::Bar', 'index.html');
Extract embedded file from the C<DATA> section of a class.
Extract embedded file from the C<DATA> section of a class, all files will be
cached once they have been accessed for the first time.
say for keys %{$loader->data('Foo::Bar')};
Expand Down

0 comments on commit 9e8228e

Please sign in to comment.