diff options
author | dakkar <dakkar@luxion> | 2005-10-18 13:41:42 +0000 |
---|---|---|
committer | dakkar <dakkar@luxion> | 2005-10-18 13:41:42 +0000 |
commit | 1b22e99fb9fc14c211795f14730a1ae4b337e35f (patch) | |
tree | 413bb1c33c703ab55d99cc77d18050bc1dc6ce9f /lib/WebCoso | |
parent | r669@narval2: dakkar | 2005-10-03 18:49:13 +0200 (diff) | |
download | WebCoso-1b22e99fb9fc14c211795f14730a1ae4b337e35f.tar.gz WebCoso-1b22e99fb9fc14c211795f14730a1ae4b337e35f.tar.bz2 WebCoso-1b22e99fb9fc14c211795f14730a1ae4b337e35f.zip |
inizio del progetto: si possono definire semplici risorse via file di configurazione
git-svn-id: svn://luxion/repos/WebCoso/trunk@3 fcb26f47-9200-0410-b104-b98ab5b095f3
Diffstat (limited to 'lib/WebCoso')
-rw-r--r-- | lib/WebCoso/Config.pm | 58 | ||||
-rw-r--r-- | lib/WebCoso/Config/Resource.pm | 62 |
2 files changed, 120 insertions, 0 deletions
diff --git a/lib/WebCoso/Config.pm b/lib/WebCoso/Config.pm new file mode 100644 index 0000000..68968da --- /dev/null +++ b/lib/WebCoso/Config.pm @@ -0,0 +1,58 @@ +package WebCoso::Config; +use strict; +use warnings; +use vars '@resources'; + +sub read_scalar { + my ($class,$content,$filename)=@_; + $WebCoso::Config::Helpers::FILENAME=$filename; + $content=<<'EOF'.$content; +package WEBCOSO::CONFIG; +WebCoso::Config::Helpers->import(); +EOF + eval $content; + if ($@) { + die("Error reading configuration from $filename: $@\n"); + } + else { + return 1; + } +} + +sub add_resource { + my ($class,$resource)=@_; + push @resources,$resource; +} + +sub get_all_resources { + return @resources; +} + +package WebCoso::Config::Helpers; +use Path::Class; +use WebCoso::Config::Resource; +use Exporter::Lite; +use vars qw($FILENAME @EXPORT); + +@EXPORT=qw(res); + +sub res { + my $dest_filename=pop @_; + my $pipeline_name=pop @_; + my @source_files=@_; + + my $config_dir=file($FILENAME)->parent->absolute; + + $dest_filename=file($dest_filename)->absolute($config_dir); + for (@source_files) { + $_=file($_)->absolute($config_dir); + } + + WebCoso::Config::Resource->new({ + source=>[@source_files], + pipeline=>$pipeline_name, + destination=>$dest_filename + }); +} + +1; diff --git a/lib/WebCoso/Config/Resource.pm b/lib/WebCoso/Config/Resource.pm new file mode 100644 index 0000000..b499fec --- /dev/null +++ b/lib/WebCoso/Config/Resource.pm @@ -0,0 +1,62 @@ +package WebCoso::Config::Resource; +use strict; +use warnings; +use Class::Std; +use WebCoso::Config; + +{ + +my %sources_of :ATTR( :init_arg<source> ); +my %pipelines_of :ATTR( :init_arg<pipeline> ); +my %dest_of :ATTR( :init_arg<destination> ); + +sub BUILD { + my ($self,$ident,$args_ref)=@_; + WebCoso::Config->add_resource($self); +} + +sub axes { + return 'filename'; +} + +sub axis { + my ($self,$axis_name)=@_; + if ($axis_name eq 'filename') { + return @{$sources_of{ident($self)}}; + } + else { + return; + } +} + +sub datastream { + my ($self,$axis_name,$axis_value,@rest)=@_; + if (@rest==0 and $axis_name eq 'filename') { + if ( grep { $_ eq $axis_value } @{$sources_of{ident($self)}} ) { + return _read_file($axis_value); + } + } + else { + return; + } +} + +sub properties { + return (); +} + +sub collections { + return (); +} + +sub _read_file :PRIVATE { + my ($filename)=@_; + + local $/; + open my $fh,'<:raw',$filename or die "Can't open $filename: $!\n"; + return scalar <$fh>; +} + +} + +1; |