Move the default format inside App::MusicExpo
[app-musicexpo.git] / lib / App / MusicExpo.pm
index 1595f71cf4933a084bb073cecd562aaf2ff5e4d9..3194665a5a0a91bc9d9583425e27c7b06d0a6757 100644 (file)
@@ -1,5 +1,6 @@
 package App::MusicExpo 0.001;
 use v5.14;
+use strict;
 use warnings;
 
 use Audio::FLAC::Header qw//;
@@ -17,10 +18,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,
@@ -86,11 +89,25 @@ 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( $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 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.010945 seconds and 4 git commands to generate.