Separating code, configuration, and presentation.

brian_d_foy on 2003-01-05T01:06:53

In the January 2003 issue of The Perl Review, I write about separating code, configuration, and presentation.

Since I was working with MP3 files today, I decided to separate code, configuration, and logic in my little mp3info script which I use when I work on Mac::iTunes. The script does not come with the module, although you can get it from CVS (which has the full file with documentation).

use ConfigReader::Simple;
use MP3::Info;
use Text::Template qw(fill_in_file);

my $Config = "$ENV{HOME}/.mp3info.rc";

my $config = ConfigReader::Simple->new( $Config ); die "Could not get configuration" unless ref $config;

my $template = $config->template; die "Could not find template [$template]!" unless -e $template;

foreach my $file ( @ARGV ) { my $tag = get_mp3tag($file) or die "No TAG info"; my $info = get_mp3info($file) or die "No info";

my $hash = { %$tag, %$info, file => $file, size => -s $file };

print fill_in_file( $template, HASH => $hash ); }


My template is really simple---I just wanted to verify that iTunes affected the files.

	{
	join "\n\t",
			$file,
			$TITLE,
			$ARTIST,
			$SIZE,
			$size,
	}


As I played with iTunes, I fiddled with the template to produce whatever reports I needed.

Now I just need to add command line switches to override the configuration values.