From 39cbed22c071aea381101a9612485118692144d0 Mon Sep 17 00:00:00 2001 From: Olivier Thauvin Date: Fri, 9 Jun 2006 21:20:47 +0000 Subject: - add settree() function --- lib/MDV/Distribconf.pm | 29 +++++++++++++++++++++++++++++ t/01distribconf.t | 22 +++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/MDV/Distribconf.pm b/lib/MDV/Distribconf.pm index 0779db0..ecb58fb 100644 --- a/lib/MDV/Distribconf.pm +++ b/lib/MDV/Distribconf.pm @@ -219,6 +219,35 @@ sub loadtree { return 1; } +=head2 $distrib->settree($spec) + +Virtual set the internal structure of the distrib. + +$spec can be 'mandrake' or 'mandriva' to automatically load a know structure +(old and new fascion, or a hashref: + + mediadir => 'media', + infodir => 'media/media_info', + +=cut + +sub settree { + my ($distrib, $spec) = @_; + + if (ref($spec) eq 'HASH') { + foreach (qw(infodir mediadir)) { + $distrib->{$_} = $spec->{$_} || ''; + } + } elsif ($spec && $spec =~ /mandrake/i) { + $distrib->{infodir} = "Mandrake/base"; + $distrib->{mediadir} = "Mandrake"; + } else { # finally it can be everything, we do not care + $distrib->{infodir} = "media/media_info"; + $distrib->{mediadir} = "media"; + } +} + + =head2 $distrib->parse_hdlists($hdlists) Reads the F file whose path is given by the parameter $hdlist, diff --git a/t/01distribconf.t b/t/01distribconf.t index 8899d40..685718b 100644 --- a/t/01distribconf.t +++ b/t/01distribconf.t @@ -3,7 +3,7 @@ # $Id$ use strict; -use Test::More tests => 16; +use Test::More tests => 22; use_ok('MDV::Distribconf'); @@ -12,6 +12,7 @@ ok(my $dconf = MDV::Distribconf->new('/dev/null'), "Can get new MDV::Distribconf ok(!$dconf->load(), "loading wrong distrib give error"); } +{ ok(my $dconf = MDV::Distribconf->new('test'), "Can get new MDV::Distribconf"); ok($dconf->load(), "Can load conf"); @@ -28,4 +29,23 @@ ok($dconf->getpath(undef, 'media_info') =~ m!^/*media/media_info/?$!, "Can get m ok($dconf->getfullpath(undef, 'media_info') =~ m!^/*test/+media/media_info/?$!, "Can get media_info fullpath"); # vim color: */ ok($dconf->getpath('main', 'path') =~ m!^/*media/+main/?$!, "Can get media path"); # vim color: */ ok($dconf->getfullpath('main', 'path') =~ m!^/*test/*media/+main/?$!, "Can get media fullpath"); # vim color: */ +} +{ +ok(my $dconf = MDV::Distribconf->new('not_exists'), "Can get new MDV::Distribconf"); +$dconf->settree(); +ok($dconf->getpath(undef, 'media_info') =~ m!^/*media/media_info/?$!, "Can get media_info path"); # vim color: */ +} +{ +ok(my $dconf = MDV::Distribconf->new('not_exists'), "Can get new MDV::Distribconf"); +$dconf->settree('manDraKE'); +ok($dconf->getpath(undef, 'media_info') =~ m!^/*Mandrake/base/?$!, "Can get media_info path"); # vim color: */ +} +{ +ok(my $dconf = MDV::Distribconf->new('not_exists'), "Can get new MDV::Distribconf"); +$dconf->settree({ + mediadir => 'mediadir', + infodir => 'infodir', +}); +ok($dconf->getpath(undef, 'media_info') =~ m!^/*infodir/?$!, "Can get media_info path"); # vim color: */ +} -- cgit v1.2.1