]> iEval git - app-musicexpo.git/blobdiff - lib/App/MusicExpo.pm
Use the escaping in HTML::Template::Compiled
[app-musicexpo.git] / lib / App / MusicExpo.pm
index 1595f71cf4933a084bb073cecd562aaf2ff5e4d9..475ef80f971dba4595ef3975a2637f997e9d531d 100644 (file)
@@ -1,13 +1,12 @@
 package App::MusicExpo 0.001;
 use v5.14;
+use strict;
 use warnings;
 
 use Audio::FLAC::Header qw//;
-use HTML::Entities qw/encode_entities/;
 use HTML::Template::Compiled qw//;
 use Memoize qw/memoize/;
 use MP3::Tag qw//;
-use URI::Escape qw/uri_escape/;
 
 use DB_File qw//;
 use File::Basename qw/fileparse/;
@@ -17,10 +16,12 @@ use Storable qw/thaw freeze/;
 
 ##################################################
 
+my $default_template;
+
 our $prefix='/music/';
 our $cache='cache.db';
 our $caching=1;
-our $template='index.tmpl';
+our $template='';
 
 GetOptions (
   "template=s" => \$template,
@@ -32,13 +33,12 @@ GetOptions (
 
 sub fix{
   utf8::decode($_[0]);
-  encode_entities($_[0])
 }
 
 sub flacinfo{
   my $file=$_[0];
   my $flac=Audio::FLAC::Header->new($file);
-  $file = $prefix . uri_escape scalar fileparse $file;
+  $file = $prefix . scalar fileparse $file;
 
   freeze +{
        format => 'FLAC',
@@ -56,7 +56,7 @@ sub flacinfo{
 sub mp3info{
   my $file=$_[0];
   my $mp3=MP3::Tag->new($file);
-  $file = $prefix . uri_escape scalar fileparse $file;
+  $file = $prefix . scalar fileparse $file;
 
   freeze +{
        format => 'MP3',
@@ -86,11 +86,28 @@ sub run {
        push @files, thaw mp3info $file if $file =~ /.mp3$/i;
   }
 
-  my $ht=HTML::Template::Compiled->new(filename => $template);
+  my $ht=HTML::Template::Compiled->new(
+       default_escape => 'HTML',
+       $template eq '' ? (scalarref => \$default_template) : (filename => $template),
+  );
   $ht->param(files=>[sort { $a->{title} cmp $b->{title} } @files]);
   print $ht->output;
 }
 
+$default_template = <<'HTML';
+<!DOCTYPE html>
+<title>Music</title>
+<meta charset="utf-8">
+<link rel="stylesheet" href="/music.css">
+
+<table border>
+<thead>
+<tr><th>Title<th>Artist<th>Album<th>Genre<th>Track<th>Year<th>Type
+<tbody><tmpl_loop files>
+<tr><td><a href="<tmpl_var ESCAPE=URL path>"><tmpl_var title></a><td><tmpl_var artist><td><tmpl_var album><td><tmpl_var genre><td><tmpl_var tracknumber>/<tmpl_var tracktotal><td><tmpl_var year><td><tmpl_var format></tmpl_loop>
+</table>
+HTML
+
 1;
 
 __END__
@@ -122,7 +139,7 @@ where the title is a download link.
 
 =item B<--template> I<template>
 
-Path to the HTML::Template::Compiled template used for generating the music table. Defaults to 'index.tmpl'.
+Path to the HTML::Template::Compiled template used for generating the music table. If '' (empty), uses the default format. Is empty by default.
 
 =item B<--prefix> I<prefix>
 
This page took 0.020321 seconds and 4 git commands to generate.