Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Saturday January 04, 2003
08:06 PM

Separating code, configuration, and presentation.

[ #9767 ]

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.