source: trunk/soft/ObsData/ObsData/Event.pm @ 167

Last change on this file since 167 was 167, checked in by thauvin, 18 years ago
  • add documentation
  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1# $Id$
2
3use strict;
4use warnings;
5
6package ObsData::Event;
7
8=head1 NAME
9
10ObsData::Event - A simple class to manage message between backend
11and main software.
12
13=head1 SYNOPSIS
14
15    my $callback = sub {
16        my ($events) = @_;
17        print $events->message . "\n";
18    }
19
20    my $oe = ObsData::Event->new('id', 'what should I do');
21
22    $callback($oe);
23
24=head1 METHODS
25
26=head2 new($id $message)
27
28Create a new ObsData::Event object to handle $message with $id
29
30=cut
31
32sub new {
33    my ($class, $id, $message) = @_;
34   
35    if(!($id && $message)) {
36        return undef;
37    }
38   
39    bless(
40        {
41            id => $id,
42            message => $message,
43            test => {},
44            test_order => [],
45        },
46        $class
47    );
48}
49
50=head2 id
51
52Return the id of the object
53
54=cut
55
56sub id {
57    my ($self) = @_;
58    return($self->{id});
59}
60
61=head2 message
62
63Return the message handle by the object
64
65=cut
66
67sub message {
68    my ($self) = @_;
69    return($self->{message});
70}
71
72=head2 add_test($test_id, $message, $result)
73
74Add a new test into the object.
75
76=cut
77
78sub add_test {
79    my ($self, $test_id, $message, $result) = @_;
80    if (!exists($self->{test}{$test_id})) {
81        push(@{$self->{test_order}}, $test_id);
82    }
83    $self->{test}{$test_id}{message} ||= $message;
84    $self->{test}{$test_id}{result} = $result;
85}
86
87=head2 list_test
88
89List test currently stored into the object. Return the list of test id.
90
91=cut
92
93sub list_test {
94    my ($self) = @_;
95    return(@{$self->{test_order}});
96}
97
98=head2 test_message($test_id)
99
100Return the message associated to a test.
101
102=cut
103
104sub test_message {
105    my ($self, $test_id) = @_;
106    return($self->{test}{$test_id}{message});
107}
108
109=head2 test_result($test_id)
110
111Return the result associated to a test
112
113=cut
114
115sub test_result {
116    my ($self, $test_id) = @_;
117    return($self->{test}{$test_id}{result});
118}
119
1201;
121
122__END__
123
124=head1 AUTHOR
125
126Olivier Thauvin <olivier.thauvin@aerov.jussieu.fr>
127
128=cut
Note: See TracBrowser for help on using the repository browser.