Skip to content

Commit

Permalink
improve mtime attribute in Mojo::Asset::Memory to default to the valu…
Browse files Browse the repository at this point in the history
…e of $^T
  • Loading branch information
kraih committed Jan 9, 2016
1 parent cb3dbdd commit ee0f220
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -6,6 +6,8 @@
- Added SNI support to all built-in web servers. (bpmedley, sri)
- Added next attribute to Mojo::Transaction::HTTP.
- Updated jQuery to version 2.2.0.
- Improve mtime attribute in Mojo::Asset::Memory to default to the value of
$^T.

6.39 2016-01-03
- Updated links to Mojolicious website.
Expand Down
7 changes: 2 additions & 5 deletions lib/Mojo/Asset/Memory.pm
Expand Up @@ -4,12 +4,9 @@ use Mojo::Base 'Mojo::Asset';
use Mojo::Asset::File;
use Mojo::Util 'spurt';

# Last modified default
my $MTIME = time;

has 'auto_upgrade';
has max_memory_size => sub { $ENV{MOJO_MAX_MEMORY_SIZE} || 262144 };
has mtime => sub {$MTIME};
has mtime => sub {$^T};

sub add_chunk {
my ($self, $chunk) = @_;
Expand Down Expand Up @@ -120,7 +117,7 @@ C<MOJO_MAX_MEMORY_SIZE> environment variable or C<262144> (256KB).
my $mtime = $mem->mtime;
$mem = $mem->mtime(1408567500);
Modification time of asset, defaults to the time this class was loaded.
Modification time of asset, defaults to the value of C<$^T>.
=head1 METHODS
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/asset.t
Expand Up @@ -32,7 +32,7 @@ is $mem->contains('abc'), 0, '"abc" at position 0';
is $mem->contains('bc'), 1, '"bc" at position 1';
is $mem->contains('db'), -1, 'does not contain "db"';
is $mem->size, 3, 'right size';
ok $mem->mtime > (time - 100), 'right mtime';
is $mem->mtime, $^T, 'right mtime';
is $mem->mtime, Mojo::Asset::Memory->new->mtime, 'same mtime';
my $mtime = $mem->mtime;
is $mem->mtime($mtime + 23)->mtime, $mtime + 23, 'right mtime';
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/static_lite_app.t
Expand Up @@ -182,7 +182,7 @@ $t->get_ok('/hello4.txt' => {Range => 'bytes=0-0'})->status_is(416)
$t->get_ok('/hidden')->status_is(404)->content_unlike(qr/Unreachable file/);

# Base64 static inline file, If-Modified-Since
my $modified = Mojo::Date->new->epoch(time - 3600);
my $modified = Mojo::Date->new->epoch($^T - 1);
$t->get_ok('/static.txt' => {'If-Modified-Since' => $modified})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')->content_is("test 123\nlalala");
Expand All @@ -196,7 +196,7 @@ $t->get_ok('/static.txt')->status_is(200)
->header_is('Accept-Ranges' => 'bytes')->content_is("test 123\nlalala");

# Base64 static inline file, If-Modified-Since
$modified = Mojo::Date->new->epoch(time - 3600);
$modified = Mojo::Date->new->epoch($^T - 1);
$t->get_ok('/static.txt' => {'If-Modified-Since' => $modified})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')->content_is("test 123\nlalala");
Expand Down

0 comments on commit ee0f220

Please sign in to comment.