diff options
Diffstat (limited to 'lib/WebCoso/Config/Resource.pm')
-rw-r--r-- | lib/WebCoso/Config/Resource.pm | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/WebCoso/Config/Resource.pm b/lib/WebCoso/Config/Resource.pm index 4b5cd60..fc80d41 100644 --- a/lib/WebCoso/Config/Resource.pm +++ b/lib/WebCoso/Config/Resource.pm @@ -2,16 +2,23 @@ package WebCoso::Config::Resource; use strict; use warnings; use Class::Std; +use Scalar::Util 'weaken'; +use List::MoreUtils 'any'; use WebCoso::Config; +use WebCoso::X; { -my %sources_of :ATTR( :init_arg<source> :get<sources>); +my %sources_of :ATTR( :init_arg<sources> :get<sources>); my %pipelines_of :ATTR( :init_arg<pipeline> :get<pipeline>); my %dest_of :ATTR( :init_arg<destination> :get<destination>); +my %collections_of :ATTR( :get<collections_ref> ); sub BUILD { my ($self,$ident,$args_ref)=@_; + + $collections_of{$ident}=[]; + WebCoso::Config->add_resource($self); } @@ -48,14 +55,34 @@ sub properties { } sub collections { - return (); + my ($self)=@_; + + return @{ $self->get_collections_ref() }; +} + +sub add_coll { + my ($self, $collection)=@_; + + return if any { $_ eq $collection } @{ $self->get_collections_ref() }; + + my $weak_collection = $collection; + weaken $weak_collection; + + push @{ $self->get_collections_ref() }, $weak_collection; + + $collection->add_res($self); + + return; } sub _read_file :PRIVATE { my ($filename)=@_; local $/; - open my $fh,'<:raw',$filename or die "Can't open $filename: $!\n"; + open my $fh,'<:raw',$filename + or WebCoso::X::OpenError->throw( + filename => $filename, + error => $!); return scalar <$fh>; } |