Move the default format inside App::MusicExpo
authorMarius Gavrilescu <Marius Gavrilescu>
Sat, 17 Aug 2013 20:57:49 +0000 (23:57 +0300)
committerMarius Gavrilescu <Marius Gavrilescu>
Sat, 17 Aug 2013 21:06:26 +0000 (00:06 +0300)
MANIFEST
index.tmpl [deleted file]
lib/App/MusicExpo.pm
musicexpo

index b6270545ba848ec6bcd2134bd8ebb91c707a46bd..40b0c0a457e2ca79ec28a458e9a0ccd8f9f97f5b 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -5,6 +5,5 @@ README
 t/App-MusicExpo.t
 lib/App/MusicExpo.pm
 musicexpo
-index.tmpl
 empty.mp3
 empty.flac
diff --git a/index.tmpl b/index.tmpl
deleted file mode 100644 (file)
index cc275ad..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<!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>
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>
 
index c408bb4ff3013e8bde3453551ad51501c922a7ef..476842433b9991559dab8c20b508b34cf4dde033 100755 (executable)
--- a/musicexpo
+++ b/musicexpo
@@ -13,7 +13,7 @@ musicexpo - script which generates a HTML table of music tags
 
 =head1 SYNOPSIS
 
-    # Creates a table with the songs a.mp3 and b.flac using the template 'index.tmpl' and caching the tags in the file 'cache.db'. The download links point to /music/a.mp3 and /music/b.mp3
+    # Creates a table with the songs a.mp3 and b.flac using the default template and caching the tags in the file 'cache.db'. The download links point to /music/a.mp3 and /music/b.mp3
     musicexpo a.mp3 b.flac
 
     # Disables caching, and the download links point to /download/a.flac, /download/b.flac, /download/c.flac
@@ -40,7 +40,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.014418 seconds and 4 git commands to generate.