aboutsummaryrefslogtreecommitdiff
path: root/lib/WebCoso/Config/Resource.pm
blob: 4b5cd6026e5fac786b089dfafb69809c8f7098ca (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
package WebCoso::Config::Resource; 
use strict;
use warnings;
use Class::Std;
use WebCoso::Config;
 
{
 
my %sources_of :ATTR( :init_arg<source> :get<sources>);
my %pipelines_of :ATTR( :init_arg<pipeline> :get<pipeline>);
my %dest_of :ATTR( :init_arg<destination> :get<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 @{ $self->get_sources() };
    }
    else {
        return;
    }
}
 
sub datastream {
    my ($self,$axis_name,$axis_value,@rest)=@_;
    if (@rest==0 and $axis_name eq 'filename') {
        if ( grep { $_ eq $axis_value }
                 @{ $self->get_sources() }
             ) {
            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;