aboutsummaryrefslogtreecommitdiff
path: root/lib/WebCoso/Collections.pm
blob: f0f9815b769722e7504b9a634b2265820208a032 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package WebCoso::Collections; 
use strict;
use warnings;
use Class::Std;
use List::MoreUtils 'any';
 
{
my %collections_of :ATTR( :get<collections_ref> );
 
sub BUILD {
    my ($self,$ident,$args_ref)=@_;
 
    $collections_of{$ident} = [];
}
 
sub add_collection {
    my ($self$collection)=@_;
 
    return if any { $_ eq $collection } $self->get_all_collections();
 
    push @{ $self->get_collections_ref() }, $collection;
}
 
sub get_all_collections {
    my ($self)=@_;
    return @{ $self->get_collections_ref() };
}
 
sub get_root_collections {
    my ($self)=@_;
 
    return grep {
        $_->get_parents() == 0
    $self->get_all_collections();
}
 
sub get_leaf_collections {
    my ($self)=@_;
 
    return grep {
        $_->get_children() == 0
    $self->get_all_collections();
}
 
sub get_axes {
    return 'language';
}
 
sub get_axis_values {
    my ($self,$axis_name)=@_;
    if ($axis_name eq 'language') {
        return $self->_get_languages();
    }
    else {
        return;
    }
}
 
sub _get_languages {
    my ($self)=@_;
    my %langs=();
 
    for my $collection ($self->get_all_collections()) {
        @langs$collection->get_axis_values('language') } = ();
    }
 
    delete $langs{''};
 
    return keys %langs;
}
 
}
 
1;