diff options
Diffstat (limited to 'lib/WebCoso/Collection.pm')
-rw-r--r-- | lib/WebCoso/Collection.pm | 133 |
1 files changed, 0 insertions, 133 deletions
diff --git a/lib/WebCoso/Collection.pm b/lib/WebCoso/Collection.pm deleted file mode 100644 index 42442f1..0000000 --- a/lib/WebCoso/Collection.pm +++ /dev/null @@ -1,133 +0,0 @@ -package WebCoso::Collection; -use strict; -use warnings; -use Class::Std; -use Scalar::Util 'weaken'; -use List::MoreUtils 'any'; -use WebCoso::Config; - -{ -my %names_of :ATTR( :get<names> ); -my %parents_of :ATTR( :get<parents_ref> ); -my %children_of :ATTR( :get<children_ref> ); -my %resources_of :ATTR( :init_arg<resources> :get<resources_ref> ); - -sub BUILD { - my ($self,$ident,$args_ref)=@_; - - my $names=$args_ref->{name}; - # trasformo un nome semplice in un nome "per qualsiasi lingua" - $names={''=>$names} unless ref($names) eq 'HASH'; - $names_of{$ident}=$names; - - my $parents=$args_ref->{parents} || []; - $parents_of{$ident}=$parents; - $_->add_child($self) for @$parents; - - my $children=$args_ref->{children} || []; - $children_of{$ident}=$children; - $_->add_parent($self) for @$children; - - $resources_of{$ident}=[]; - - WebCoso::Config->add_collection($self); - - return; -} - -sub get_axes { - return 'language'; -} - -sub get_axis_values { - my ($self,$axis_name)=@_; - if ($axis_name eq 'language') { - return grep { $_ } keys %{ $self->get_names() } - } - else { - return; - } -} - -sub get_properties { - my ($self,$axis_name,$axis_value,@rest)=@_; - - if (@rest==0 and $axis_name eq 'language') { - if ( any { $_ eq $axis_value } - keys %{ $self->get_names() } - ) { - return { - name => $self->get_names()->{$axis_value} - }; - } - elsif (exists ${$self->get_names()}{''}) { - return { - name => $self->get_names()->{''} - }; - } - else { - return; - } - } -} - -sub add_child { - my ($self,$child)=@_; - - return if any { $_ eq $child } @{ $self->get_children_ref() }; - - push @{ $self->get_children_ref() },$child; - $child->add_parent($self); - - return; -} -sub add_parent { - my ($self,$parent)=@_; - - return if any { $_ eq $parent } @{ $self->get_parents_ref() }; - - my $weak_parent=$parent; - weaken $weak_parent; - - push @{ $self->get_parents_ref() },$weak_parent; - $parent->add_child($self); - - return; -} -sub add_res { - my ($self, @resources)=@_; - - # creo una tabellina di look-up per evitare i duplicati - # NOTA: le chiavi sono stringhe, non ref, non si può usare per - # pescare gli oggetti - my %res_key; - @res_key{ @{ $self->get_resources_ref() } } = (); - - RESOURCES: - for my $res (@resources) { - next RESOURCES if exists $res_key{$res}; - - push @{ $self->get_resources_ref() }, $res; - $res_key{$res}=undef; - $res->add_coll($self); - } - - return; -} - -sub get_parents { - my ($self)=@_; - return @{ $self->get_parents_ref() }; -} -sub get_children { - my ($self)=@_; - return @{ $self->get_children_ref() }; -} -sub get_resources { - my ($self)=@_; - return @{ $self->get_resources_ref() }; -} - -} - -1; |