Skip to content

Commit

Permalink
added experimental is_file method to Mojo::Asset and Mojo::Asset::File
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 22, 2011
1 parent 61e18b2 commit f17b082
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -3,6 +3,8 @@ This file documents the revision history for Perl extension Mojolicious.
2.05 2011-10-22 00:00:00
- Added EXPERIMENTAL max_memory_size attribute to
Mojo::Asset::Memory.
- Added EXPERIMENTAL is_file method to Mojo::Asset and
Mojo::Asset::File.
- Improved start_tls method in Mojo::IOLoop by allowing it to accept
more options.
- Improved MOJO_MAX_MEMORY_SIZE handling by moving it from
Expand Down
16 changes: 13 additions & 3 deletions lib/Mojo/Asset.pm
Expand Up @@ -10,9 +10,12 @@ has start_range => 0;
sub add_chunk { croak 'Method "add_chunk" not implemented by subclass' }
sub contains { croak 'Method "contains" not implemented by subclass' }
sub get_chunk { croak 'Method "get_chunk" not implemented by subclass' }
sub move_to { croak 'Method "move_to" not implemented by subclass' }
sub size { croak 'Method "size" not implemented by subclass' }
sub slurp { croak 'Method "slurp" not implemented by subclass' }

sub is_file {undef}

sub move_to { croak 'Method "move_to" not implemented by subclass' }
sub size { croak 'Method "size" not implemented by subclass' }
sub slurp { croak 'Method "slurp" not implemented by subclass' }

1;
__END__
Expand Down Expand Up @@ -70,6 +73,13 @@ Check if asset contains a specific string.
Get chunk of data starting from a specific position.
=head2 C<is_file>
my $false = $asset->is_file;
False.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<move_to>
$asset = $asset->move_to('/foo/bar/baz.txt');
Expand Down
9 changes: 9 additions & 0 deletions lib/Mojo/Asset/File.pm
Expand Up @@ -127,6 +127,8 @@ sub get_chunk {
return $buffer;
}

sub is_file {1}

sub move_to {
my ($self, $path) = @_;

Expand Down Expand Up @@ -247,6 +249,13 @@ Check if asset contains a specific string.
Get chunk of data starting from a specific position.
=head2 C<is_file>
my $true = $file->is_file;
True.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<move_to>
$file = $file->move_to('/foo/bar/baz.txt');
Expand Down
6 changes: 3 additions & 3 deletions t/mojo/message.t
Expand Up @@ -261,13 +261,13 @@ $req->parse('-Type: text/');
is $req->content->progress, 0, 'right progress';
$req->parse("plain\x0d\x0aContent-Length: 27\x0d\x0a\x0d\x0aHell");
is $req->content->progress, 4, 'right progress';
is $req->content->asset->isa('Mojo::Asset::Memory'), 1, 'stored in memory';
is $req->content->asset->is_file, undef, 'stored in memory';
$req->parse("o World!\n");
is $req->content->progress, 13, 'right progress';
is $req->content->asset->isa('Mojo::Asset::File'), 1, 'stored in file';
is $req->content->asset->is_file, 1, 'stored in file';
$req->parse("1234\nlalalala\n");
is $req->content->progress, 27, 'right progress';
is $req->content->asset->isa('Mojo::Asset::File'), 1, 'stored in file';
is $req->content->asset->is_file, 1, 'stored in file';
ok $req->is_finished, 'request is finished';
is $req->method, 'GET', 'right method';
is $req->version, '1.0', 'right version';
Expand Down

0 comments on commit f17b082

Please sign in to comment.