Skip to content

Commit

Permalink
added experimental max_memory_size attribute to Mojo::Asset::Memory
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 22, 2011
1 parent 8500233 commit 61e18b2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,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.
- 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
2 changes: 1 addition & 1 deletion lib/Mojo/Asset.pm
Expand Up @@ -84,7 +84,7 @@ Size of asset data in bytes.
=head2 C<slurp>
my $string = $file->slurp;
my $string = $asset->slurp;
Read all asset data at once.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Asset/File.pm
Expand Up @@ -193,7 +193,8 @@ L<Mojo::Asset::File> is a container for file assets.
=head1 ATTRIBUTES
L<Mojo::Asset::File> implements the following attributes.
L<Mojo::Asset::File> inherits all attributes from L<Mojo::Asset> and
implements the following new ones.
=head2 C<cleanup>
Expand Down
21 changes: 19 additions & 2 deletions lib/Mojo/Asset/Memory.pm
Expand Up @@ -5,6 +5,8 @@ use Carp 'croak';
use IO::File;
use Mojo::Asset::File;

has max_memory_size => sub { $ENV{MOJO_MAX_MEMORY_SIZE} || 262144 };

# "There's your giraffe, little girl.
# I'm a boy.
# That's the spirit. Never give up."
Expand All @@ -18,7 +20,7 @@ sub add_chunk {
my ($self, $chunk) = @_;
$self->{content} .= $chunk if defined $chunk;
return Mojo::Asset::File->new->add_chunk($self->slurp)
if $self->size > ($ENV{MOJO_MAX_MEMORY_SIZE} || 262144);
if $self->size > $self->max_memory_size;
return $self;
}

Expand Down Expand Up @@ -77,6 +79,21 @@ Mojo::Asset::Memory - In-memory asset
L<Mojo::Asset::Memory> is a container for in-memory assets.
=head1 ATTRIBUTES
L<Mojo::Asset::Memory> inherits all attributes from L<Mojo::Asset> and
implements the following new ones.
=head2 C<max_memory_size>
my $size = $mem->max_memory_size;
$mem = $mem->max_memory_size(1024);
Maximum asset size in bytes, only attempt upgrading to a L<Mojo::Asset::File>
object after reaching this limit, defaults to the value of
C<MOJO_MAX_MEMORY_SIZE> or C<5262144>.
Note that this attribute is EXPERIMENTAL and might change without warning!
=head1 METHODS
L<Mojo::Asset::Memory> inherits all methods from L<Mojo::Asset> and
Expand Down Expand Up @@ -121,7 +138,7 @@ Size of asset data in bytes.
=head2 C<slurp>
my $string = $file->slurp;
my $string = mem->slurp;
Read all asset data at once.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -338,7 +338,8 @@ L<Mojo::Headers> implements the following attributes.
my $size = $headers->max_line_size;
$headers = $headers->max_line_size(1024);
Maximum line size in bytes, defaults to C<10240>.
Maximum line size in bytes, defaults to the value of C<MOJO_MAX_LINE_SIZE> or
C<10240>.
Note that this attribute is EXPERIMENTAL and might change without warning!
=head1 METHODS
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojo/Message.pm
Expand Up @@ -635,7 +635,8 @@ to L<Mojo::JSON>.
my $size = $message->max_message_size;
$message = $message->max_message_size(1024);
Maximum message size in bytes, defaults to C<5242880>.
Maximum message size in bytes, defaults to the value of
C<MOJO_MAX_MESSAGE_SIZE> or C<5242880>.
=head1 METHODS
Expand Down Expand Up @@ -805,7 +806,7 @@ Remove leftover data from message parser.
$message->max_line_size(1024);
Maximum line size in bytes.
Alias for L<Mojo::Headers/"max_line_size">.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<param>
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -407,7 +407,8 @@ Mask outgoing frames with XOR cipher and a random 32bit key.
my $size = $ws->max_websocket_size;
$ws = $ws->max_websocket_size(1024);
Maximum WebSocket message size in bytes, defaults to C<262144>.
Maximum WebSocket message size in bytes, defaults to the value of
C<MOJO_MAX_WEBSOCKET_SIZE> or C<262144>.
=head1 METHODS
Expand Down

0 comments on commit 61e18b2

Please sign in to comment.