Skip to content

Commit b2dc79b

Browse files
committed
fix file listing data in model
Having keys with periods in them is hard to work with, and 'stat' should be a hash anyway, to be consistent with everywhere else. Fix the format of the file listing in the model rather than forcing the template to deal with it. This should probably be different in the API, but for now adapt it here.
1 parent 763f21f commit b2dc79b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/MetaCPAN/Web/Model/API/File.pm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ sub dir {
1717
my $path = join '/', @path;
1818
my $data = $self->request("/file/dir/$path")->transform(
1919
done => sub {
20-
$_[0]->{dir};
20+
my $dir = $_[0]->{dir};
21+
for my $entry (@$dir) {
22+
my $stat = $entry->{stat} ||= {};
23+
for my $stat_entry ( map /^stat\.(.*)/ ? $1 : (),
24+
keys %$entry )
25+
{
26+
$stat->{$stat_entry}
27+
= delete $entry->{"stat.$stat_entry"};
28+
}
29+
}
30+
return $dir;
2131
}
2232
);
2333
}

root/browse.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
: 'silk-page-white'
4141
-%>" title="<% file.path %>"><% file.name %></a></td>
4242
<td class="documentation"><strong><a href="/pod/release/<% [author, release, file.path].join("/") %>" title="<% file.path %>" class="ellipsis"><% file.slop ? file.documentation ? file.documentation : file.name : "" %></a></strong></td>
43-
<td class="size" sort="<% file.directory == 0 ? file.${"stat.size"} : 0 %>"><% file.directory == 0 ? file.${"stat.size"} | format_bytes : "" %></td>
44-
<td class="mtime relatize" nowrap="nowrap" sort="<% date = datetime(file.${"stat.mtime"}).to_http; date %>"><% date %></td>
43+
<td class="size" sort="<% file.directory == 0 ? file.stat.size : 0 %>"><% file.directory == 0 ? file.stat.size | format_bytes : "" %></td>
44+
<td class="mtime relatize" nowrap="nowrap" sort="<% date = datetime(file.stat.mtime).to_http; date %>"><% date %></td>
4545
</tr>
4646
<% END %>
4747
</tbody>

0 commit comments

Comments
 (0)