1 | # $Id$ |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | package ObsData::Event; |
---|
7 | |
---|
8 | =head1 NAME |
---|
9 | |
---|
10 | ObsData::Event - A simple class to manage message between backend |
---|
11 | and 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 | |
---|
28 | Create a new ObsData::Event object to handle $message with $id |
---|
29 | |
---|
30 | =cut |
---|
31 | |
---|
32 | sub 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 | |
---|
52 | Return the id of the object |
---|
53 | |
---|
54 | =cut |
---|
55 | |
---|
56 | sub id { |
---|
57 | my ($self) = @_; |
---|
58 | return($self->{id}); |
---|
59 | } |
---|
60 | |
---|
61 | =head2 message |
---|
62 | |
---|
63 | Return the message handle by the object |
---|
64 | |
---|
65 | =cut |
---|
66 | |
---|
67 | sub message { |
---|
68 | my ($self) = @_; |
---|
69 | return($self->{message}); |
---|
70 | } |
---|
71 | |
---|
72 | =head2 add_test($test_id, $message, $result) |
---|
73 | |
---|
74 | Add a new test into the object. |
---|
75 | |
---|
76 | =cut |
---|
77 | |
---|
78 | sub 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 | |
---|
89 | List test currently stored into the object. Return the list of test id. |
---|
90 | |
---|
91 | =cut |
---|
92 | |
---|
93 | sub list_test { |
---|
94 | my ($self) = @_; |
---|
95 | return(@{$self->{test_order}}); |
---|
96 | } |
---|
97 | |
---|
98 | =head2 test_message($test_id) |
---|
99 | |
---|
100 | Return the message associated to a test. |
---|
101 | |
---|
102 | =cut |
---|
103 | |
---|
104 | sub test_message { |
---|
105 | my ($self, $test_id) = @_; |
---|
106 | return($self->{test}{$test_id}{message}); |
---|
107 | } |
---|
108 | |
---|
109 | =head2 test_result($test_id) |
---|
110 | |
---|
111 | Return the result associated to a test |
---|
112 | |
---|
113 | =cut |
---|
114 | |
---|
115 | sub test_result { |
---|
116 | my ($self, $test_id) = @_; |
---|
117 | return($self->{test}{$test_id}{result}); |
---|
118 | } |
---|
119 | |
---|
120 | 1; |
---|
121 | |
---|
122 | __END__ |
---|
123 | |
---|
124 | =head1 AUTHOR |
---|
125 | |
---|
126 | Olivier Thauvin <olivier.thauvin@aerov.jussieu.fr> |
---|
127 | |
---|
128 | =cut |
---|