root/POE-Component-YahooMessenger/trunk/lib/POE/Component/YahooMessenger/Event.pm

Revision 764 (checked in by miyagawa, 18 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package POE::Component::YahooMessenger::Event;
2 use strict;
3
4 BEGIN {
5     use POE::Component::YahooMessenger::Constants;
6
7     sub _make_body_accessor {
8         my $wantkey = shift;
9         return sub {
10             my $self = shift;
11             my @values;
12             my @params = $self->params;
13             while (my($key, $value) = splice(@params, 0, 2)) {
14                 push @values, $value if $key eq $BodyNames->{$wantkey};
15             }
16             return wantarray ? @values : $values[0];
17         };
18     }
19
20     for my $name (keys %$BodyNames) {
21         no strict 'refs';
22         *$name = _make_body_accessor($name);
23     }
24 }
25
26 sub new_from_body {
27     my($class, $code, $body) = @_;
28     bless {
29         code   => $code,
30         option => 0,            # XXX ?
31         params => [ split /$BodySeparater/, $body ],
32     }, $class;
33 }
34
35 sub new {
36     my($class, $name, $option, $params) = @_;
37     bless {
38         code   => $SendEventNames->{$name},
39         option => $option,
40         params => [ map { $BodyNames->{$_} => $params->{$_} } keys %$params ],
41     }, $class;
42 }
43
44 sub code   { shift->{code} }
45 sub name   { $ReceiveEventCodes->{shift->code} }
46 sub option { shift->{option} }
47
48 sub body   {
49     my $self = shift;
50     return join($BodySeparater, $self->params) . $BodySeparater;
51 }
52
53 sub params { @{shift->{params}} }
54
55 package POE::Component::YahooMessenger::Event::Null;
56
57 use base qw(POE::Component::YahooMessenger::Event);
58
59 sub new { bless {}, shift }
60 sub DESTROY { }
61 sub AUTOLOAD { }
62
63 1;
Note: See TracBrowser for help on using the browser.