# $Id: Conf.pm,v 1.13 2003/12/14 09:43:56 ianb Exp $
package MP3::Archive::Lint::Conf;

use strict;
use warnings;

use Cwd;

use MP3::Archive::Config;
use MP3::Archive::Lint::Skip;

use vars qw(@ISA $VERSION);

$VERSION = '0.01';
@ISA=qw(MP3::Archive::Config);

=head1 NAME

MP3::Archive::Lint::Conf - Configuration handling for mp3lint

=head1 SYNOPSIS

    $conf=MP3::Archive::Lint::Config->new([\%newopts]);
    $conf->setopts(\%opts);
    $archive=$conf->archive;
    $skip=$conf->skip;
    $debug=$conf->debug;
    $quickscan=$config->quickscan;
    $ignoreskip=$config->ignoreskip;
    $doskip=$config->skipnametests;

See L<MP3::Archive::Config(3)> for details of methods we inherit from
it.

=head1 DESCRIPTION

MP3::Archive::Lint::Conf handles configuration for L<mp3lint(1)>. It is
a subclass of MP3::Archive::Config, and extends it with
mp3lint-specific configuration information.

See L<mp3lintrc(5)> for details of the configuration file format.

=head1 PUBLIC METHODS

=cut

=head2 new

Creates an instance of MP3::Archive::Lint::Conf

Takes 1 argument, a reference to a hash of options.

Loads the appropriate config files, see L<mp3lintrc(5)> and
L<MP3::Archive::Config(3)> for details

=cut

sub new
{
	my $proto=shift;
	my $class=ref($proto) || $proto;
	my $opts=shift;
	my $defaults=join('',<DATA>);
	my $self=$class->SUPER::new({defaults   => $defaults,
								rcfile     => "$ENV{HOME}/.mp3lintrc",
								rcenv      => "MP3LINTRC",
								sysrc      => "/etc/mp3lintrc",
								apprconly  => 0});
	bless($self,$class);

	$self->{skip}=new MP3::Archive::Lint::Skip({"skip" => $self->get("lint_skip")});
	$self->{userconfig}->{debug}=0;
	$self->{userconfig}->{quickscan}=0;
	$self->{userconfig}->{ignoreskip}=0;
	$self->{userconfig}->{fix}=0;
	$self->{userconfig}->{skipnametests}=0;

	# command line overrides config file

	$self->{userconfig}->{debug}         = 1  if ($opts->{debug}         );
	$self->{userconfig}->{fix}           = 1  if ($opts->{fix}           );
	$self->{userconfig}->{quickscan}     = 1  if ($opts->{quickscan}     );
	$self->{userconfig}->{ignoreskip}    = 1  if ($opts->{ignoreskip}    );
	$self->{userconfig}->{skipnametests} = 1  if ($opts->{skipnametests} );
	$self->{userconfig}->{tools}          = $opts->{tools}          if(exists($opts->{tools}));
	$self->{userconfig}->{skiptools}      = $opts->{skiptools}      if(exists($opts->{skiptools}));
	if(exists($opts->{format_default}))
	{
		$self->setopts({"format_default" => $opts->{format_default} });
	}
	return $self;
}

=head2 archive, skip

Return references to our MP3::Archive object and
MP3::Archive::Lint::Skip object, respectively.

=cut	

sub archive       { return shift->{archive};                     }
sub skip          { return shift->{skip};                        }

=head2 debug, fix, quickscan, ignoreskip, skipnametests
	
All are accessor methods to return option flags.

=cut	

sub debug         { return shift->{userconfig}->{debug};         }
sub fix           { return shift->{userconfig}->{fix};           }
sub quickscan     { return shift->{userconfig}->{quickscan};     }
sub ignoreskip    { return shift->{userconfig}->{ignoreskip};    }
sub skipnametests { return shift->{userconfig}->{skipnametests}; }

=head2 setopts($opts)

Checks for parse errors then calls C<setopts> in the parent class.
C<$opts> is a hashref of options to set. Preserves any options
not mentioned.	

=cut


# Checks for parse errors then calls parent
sub setopts
{
	my($self,$opts)=@_;
	if(defined($self->{parseerror}) && ($self->{parseerror} ne ""))
	{
		print "$self->{me}:error parsing config: $self->{parseerror}\n";
		exit(1);
	}
	$self->SUPER::setopts($opts);
}

=head1 BUGS

None known. Please report any found to ianb@nessie.mcc.ac.uk	

=head1 SEE ALSO    

L<MP3::Archive::Config(3)>, L<mp3lint(1)>, L<mp3lintrc(5)>,
L<mp3lint-tools(3)>, L<mp3lintskip(1)>, L<mp3lintsum(1)>,
L<mp3-archive-tools(1)>

=head1 AUTHOR

Ian Beckwith <ianb@nessie.mcc.ac.uk>

=cut

1;

# defaults follow

__DATA__

#
# Variables below here are specific to mp3lintrc(5)
#

$lint_extensions=["mp3","mp2","wav","ogg","m3u","flac","au"];

$lint_various='\/Various\/';

$lint_fix=0;
$lint_skip=["^filename:caps:",
			"^filename:the:",
			"^filename:disc:"];

$lint_case='highlight';

$lint_perms_file=0644;
$lint_perms_dir=0755;

$lint_minbitrate_mp3=120; # allow 8 for vbr just under average
$lint_minbitrate_ogg=100; # 110 is default average
$lint_minsamplerate=44100;
$lint_minbitsize=16;

$lint_allow_wav=1;

$lint_maxbadframes_mp3check=0;
$lint_maxbadframes_mp3info=0;

# the last line of the config file should evaluate to 1;
1;
