Skip to content

Commit

Permalink
simplified get_data
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 21, 2012
1 parent 50ad17b commit a9ac225
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/Loader.pm
Expand Up @@ -42,7 +42,7 @@ sub get_all_data {
}

sub get_data {
my ($self, $data, $class) = @_;
my ($self, $class, $data) = @_;
return $class ? $self->get_all_data($class)->{$data} : undef;
}

Expand Down Expand Up @@ -122,13 +122,13 @@ following new ones.
=head2 C<get_all_data>
my $all = $loader->get_all_data('Some::Class');
my $all = $loader->get_all_data('Foo::Bar');
Extract all embedded files from the C<DATA> section of a class.
=head2 C<get_data>
my $data = $loader->get_data('foo_bar', 'Some::Class');
my $data = $loader->get_data('Foo::Bar', 'foo_bar');
Extract embedded file from the C<DATA> section of a class.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Command.pm
Expand Up @@ -60,7 +60,7 @@ sub rel_file { catfile(getcwd(), split /\//, pop) }

sub render_data {
my $self = shift;
Mojo::Template->new->render(Mojo::Loader->get_data(shift, ref $self), @_);
Mojo::Template->new->render(Mojo::Loader->get_data(ref $self, shift), @_);
}

sub render_to_file {
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Renderer.pm
Expand Up @@ -70,7 +70,7 @@ sub get_data_template {
}

# Find template
return Mojo::Loader->get_data($template, $self->{index}{$template});
return Mojo::Loader->get_data($self->{index}{$template}, $template);
}

sub render {
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Static.pm
Expand Up @@ -129,7 +129,7 @@ sub _get_data_file {
}

# Find file
return Mojo::Loader->get_data($rel, $self->{index}{$rel});
return Mojo::Loader->get_data($self->{index}{$rel}, $rel);
}

sub _get_file {
Expand Down
14 changes: 7 additions & 7 deletions t/mojo/loader.t
Expand Up @@ -86,9 +86,9 @@ my $unix = "@@ template1\nFirst Template\n@@ template2\r\nSecond Template\n";
open my $data, '<', \$unix;
no strict 'refs';
*{"Example::Package::UNIX::DATA"} = $data;
is $loader->get_data('template1', 'Example::Package::UNIX'),
is $loader->get_data('Example::Package::UNIX', 'template1'),
"First Template\n", 'right template';
is $loader->get_data('template2', 'Example::Package::UNIX'),
is $loader->get_data('Example::Package::UNIX', 'template2'),
"Second Template\n", 'right template';
is_deeply [sort keys %{$loader->get_all_data('Example::Package::UNIX')}],
[qw(template1 template2)], 'right DATA files';
Expand All @@ -100,9 +100,9 @@ my $windows
open $data, '<', \$windows;
no strict 'refs';
*{"Example::Package::Windows::DATA"} = $data;
is $loader->get_data('template3', 'Example::Package::Windows'),
is $loader->get_data('Example::Package::Windows', 'template3'),
"Third Template\r\n", 'right template';
is $loader->get_data('template4', 'Example::Package::Windows'),
is $loader->get_data('Example::Package::Windows', 'template4'),
"Fourth Template\r\n", 'right template';
is_deeply [sort keys %{$loader->get_all_data('Example::Package::Windows')}],
[qw(template3 template4)], 'right DATA files';
Expand All @@ -113,11 +113,11 @@ my $mixed = "@\@template5\n5\n\n@@ template6\n6\n@@ template7\n7";
open $data, '<', \$mixed;
no strict 'refs';
*{"Example::Package::Mixed::DATA"} = $data;
is $loader->get_data('template5', 'Example::Package::Mixed'), "5\n\n",
is $loader->get_data('Example::Package::Mixed', 'template5'), "5\n\n",
'right template';
is $loader->get_data('template6', 'Example::Package::Mixed'), "6\n",
is $loader->get_data('Example::Package::Mixed', 'template6'), "6\n",
'right template';
is $loader->get_data('template7', 'Example::Package::Mixed'), '7',
is $loader->get_data('Example::Package::Mixed', 'template7'), '7',
'right template';
is_deeply [sort keys %{$loader->get_all_data('Example::Package::Mixed')}],
[qw(template5 template6 template7)], 'right DATA files';
Expand Down

0 comments on commit a9ac225

Please sign in to comment.