aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2005-11-05 11:06:09 +0000
committerdakkar <dakkar@luxion>2005-11-05 11:06:09 +0000
commitda1d1cf0604da05f253d3e59c11eb92db5833244 (patch)
treecf70e9d377d131a78d3c0cf4fa1c98d32e026e47
parentspostata eccezione di file not found, cambiati i 'die' con Exception::Class, ... (diff)
downloadWebCoso-da1d1cf0604da05f253d3e59c11eb92db5833244.tar.gz
WebCoso-da1d1cf0604da05f253d3e59c11eb92db5833244.tar.bz2
WebCoso-da1d1cf0604da05f253d3e59c11eb92db5833244.zip
normalizzati i nomi dei metodi, aggiunti test per controllo duplicati
git-svn-id: svn://luxion/repos/WebCoso/trunk@20 fcb26f47-9200-0410-b104-b98ab5b095f3
-rw-r--r--lib/WebCoso/Config/Collection.pm6
-rw-r--r--lib/WebCoso/Config/Collections.pm6
-rw-r--r--lib/WebCoso/Config/Resource.pm12
-rw-r--r--t/01-config.t67
4 files changed, 64 insertions, 27 deletions
diff --git a/lib/WebCoso/Config/Collection.pm b/lib/WebCoso/Config/Collection.pm
index 6108623..961bc55 100644
--- a/lib/WebCoso/Config/Collection.pm
+++ b/lib/WebCoso/Config/Collection.pm
@@ -35,11 +35,11 @@ sub BUILD {
return;
}
-sub axes {
+sub get_axes {
return 'language';
}
-sub axis {
+sub get_axis_value {
my ($self,$axis_name)=@_;
if ($axis_name eq 'language') {
return grep { $_ } keys %{ $self->get_names() }
@@ -49,7 +49,7 @@ sub axis {
}
}
-sub properties {
+sub get_properties {
my ($self,$axis_name,$axis_value,@rest)=@_;
if (@rest==0 and $axis_name eq 'language') {
diff --git a/lib/WebCoso/Config/Collections.pm b/lib/WebCoso/Config/Collections.pm
index 7d4d9e0..9cb3bbe 100644
--- a/lib/WebCoso/Config/Collections.pm
+++ b/lib/WebCoso/Config/Collections.pm
@@ -42,11 +42,11 @@ sub get_leaf_collections {
} $self->get_all_collections();
}
-sub axes {
+sub get_axes {
return 'language';
}
-sub axis {
+sub get_axis_value {
my ($self,$axis_name)=@_;
if ($axis_name eq 'language') {
return $self->_get_languages();
@@ -61,7 +61,7 @@ sub _get_languages {
my %langs=();
for my $collection ($self->get_all_collections()) {
- @langs{ $collection->axis('language') } = ();
+ @langs{ $collection->get_axis_value('language') } = ();
}
delete $langs{''};
diff --git a/lib/WebCoso/Config/Resource.pm b/lib/WebCoso/Config/Resource.pm
index fc80d41..b21bdcd 100644
--- a/lib/WebCoso/Config/Resource.pm
+++ b/lib/WebCoso/Config/Resource.pm
@@ -20,13 +20,15 @@ sub BUILD {
$collections_of{$ident}=[];
WebCoso::Config->add_resource($self);
+
+ return;
}
-sub axes {
+sub get_axes {
return 'filename';
}
-sub axis {
+sub get_axis_value {
my ($self,$axis_name)=@_;
if ($axis_name eq 'filename') {
return @{ $self->get_sources() };
@@ -36,7 +38,7 @@ sub axis {
}
}
-sub datastream {
+sub get_datastream {
my ($self,$axis_name,$axis_value,@rest)=@_;
if (@rest==0 and $axis_name eq 'filename') {
if ( grep { $_ eq $axis_value }
@@ -50,11 +52,11 @@ sub datastream {
}
}
-sub properties {
+sub get_properties {
return ();
}
-sub collections {
+sub get_collections {
my ($self)=@_;
return @{ $self->get_collections_ref() };
diff --git a/t/01-config.t b/t/01-config.t
index d4c8e85..b0261df 100644
--- a/t/01-config.t
+++ b/t/01-config.t
@@ -22,14 +22,14 @@ is(scalar @resources,1,'una risorsa definta');
isa_ok($resources[0],'WebCoso::Config::Resource');
is_deeply(
- [$resources[0]->axes()],
+ [$resources[0]->get_axes()],
['filename'],
'un solo asse');
is_deeply(
- [$resources[0]->axis('filename')],
+ [$resources[0]->get_axis_value('filename')],
["$thisdir/src/file1.rest.txt"],
'filename');
-is($resources[0]->datastream(filename=>"$thisdir/src/file1.rest.txt"),
+is($resources[0]->get_datastream(filename=>"$thisdir/src/file1.rest.txt"),
<<'EOF','');
Titolo
======
@@ -37,11 +37,11 @@ Titolo
testo
EOF
is_deeply(
- [$resources[0]->properties()],
+ [$resources[0]->get_properties()],
[],
'no properties');
is_deeply(
- [$resources[0]->collections()],
+ [$resources[0]->get_collections()],
[],
'no collections');
}
@@ -79,22 +79,22 @@ my @collections=$collections->get_all_collections();
is(scalar @collections,1,'una collezione');
is_deeply(
- [$collections[0]->axes()],
+ [$collections[0]->get_axes()],
['language'],
'multilingua');
is_deeply(
- [$collections[0]->axis('language')],
+ [$collections[0]->get_axis_value('language')],
[],
'ma nessuna definita');
is_deeply(
- [$collections->axes()],
+ [$collections->get_axes()],
['language'],
'multilingua, insieme');
is_deeply(
- [$collections->axis('language')],
+ [$collections->get_axis_value('language')],
[],
'ma nessuna definita, insieme');
-my $props=$collections[0]->properties(language=>'');
+my $props=$collections[0]->get_properties(language=>'');
isa_ok($props,'HASH');
is_deeply(
$props,
@@ -142,23 +142,23 @@ is(scalar @collections,2,'due collezioni');
# definizione. Forse non sarĂ  sempre vero
is_deeply(
- [sort $collections[0]->axis('language')],
+ [sort $collections[0]->get_axis_value('language')],
['en', 'it'],
'due lingue');
is_deeply(
- [sort $collections->axis('language')],
+ [sort $collections->get_axis_value('language')],
['en', 'it'],
'due lingue');
is(
- $collections[0]->properties(language=>'en')->{name},
+ $collections[0]->get_properties(language=>'en')->{name},
'coll1-en',
'nome en');
is(
- $collections[0]->properties(language=>'it')->{name},
+ $collections[0]->get_properties(language=>'it')->{name},
'coll1',
'nome it');
is(
- $collections[1]->properties(language=>'it')->{name},
+ $collections[1]->get_properties(language=>'it')->{name},
'coll2',
'nome default');
@@ -249,7 +249,7 @@ my @collections=$collections->get_all_collections();
is(scalar @resources,1,'una risorsa');
is(scalar @collections,1,'una collezione');
is_deeply(
- [$resources[0]->collections()],
+ [$resources[0]->get_collections()],
[$collections[0]],
'aggancio r->c');
is_deeply(
@@ -257,3 +257,38 @@ is_deeply(
[$resources[0]],
'aggancio c->r');
}
+
+WebCoso::Config->clear();
+
+{
+my $conf_file=<<'EOF';
+$r1=res('src/file1.rest.txt','Id','dst/file.html');
+$c1=coll('coll1');
+$c2=coll('coll2');
+$c1->add_res($r1);
+$r1->add_coll($c1);
+$c2->add_res($r1);
+EOF
+
+ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
+ 'eseguita la configurazione (no strict)');
+
+my @resources=WebCoso::Config->get_all_resources();
+my $collections=WebCoso::Config->get_collections();
+my @collections=$collections->get_all_collections();
+
+is(scalar @resources,1,'una risorsa');
+is(scalar @collections,2,'due collezioni');
+is_deeply(
+ [sort $resources[0]->get_collections()],
+ [sort $collections[0],$collections[1]],
+ 'aggancio r->c');
+is_deeply(
+ [$collections[0]->get_resources()],
+ [$resources[0]],
+ 'aggancio c->r');
+is_deeply(
+ [$collections[1]->get_resources()],
+ [$resources[0]],
+ 'aggancio c->r');
+}