# XXX Hack hack hack, see View::SyntaxHighlight
language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
is_image => File::Type::WebImages::mime_type($c->stash->{blob}),
- is_binary => -B $c->stash->{blob},
+ is_binary => Gitalist::Utils::is_binary($c->stash->{blob}),
);
$c->forward('View::SyntaxHighlight')
my ($self, $c) = @_;
$c->forward('find_blob');
- if(-T $c->stash->{blob}) {
+ if(!Gitalist::Utils::is_binary($c->stash->{blob})) {
$c->response->content_type('text/plain; charset=utf-8');
} else {
my $ft = File::Type->new();
if !$sha1 || $sha1 !~ $SHA1RE;
my @search_opts;
- if ($search) {
+ if ($search and exists $search->{text}) {
$search->{type} = 'grep'
if $search->{type} eq 'commit';
@search_opts = (
return $age_str;
}
+sub is_binary {
+ my($str) = @_;
+ open my $fh, '<', \$str or return;
+ return -B $fh;
+}
+
1;
__END__
=head2 age_string
-Turns an integer number of seconds into a string..
+Turns an integer number of seconds into a string.
+
+=head2 is_binary
+
+Check whether a string is binary according to C<-B>.
=head1 AUTHORS