| 1 | package POEIKC::Plugin::IRC::ClientLite; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use 5.008_001; | ||
| 5 | our $VERSION = '0.01'; | ||
| 6 | use Sys::Hostname (); | ||
| 7 | use POE::Component::IKC::ClientLite; | ||
| 8 | |||
| 9 | sub new { | ||
| 10 | my $class = shift ; | ||
| 11 | my $self = { | ||
| 12 | ikc => undef, | ||
| 13 | RaiseError => 0, | ||
| 14 | error => undef, | ||
| 15 | @_ | ||
| 16 | }; | ||
| 17 | for (qw(ip port name serialiser timeout connect_timeout block_size)){ | ||
| 18 | $self->{create_ikc_client}->{$_} = delete $self->{$_} if exists $self->{$_}; | ||
| 19 | } | ||
| 20 | $class = ref $class if ref $class; | ||
| 21 | bless $self,$class ; | ||
| 22 | return $self ; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub ikc { | ||
| 26 | my $self = shift; | ||
| 27 | $self->{ikc} = shift if @_ >= 1; | ||
| 28 | return $self->{ikc}; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub error {shift->{error}} | ||
| 32 | |||
| 33 | sub connect { | ||
| 34 | my $self = shift; | ||
| 35 | $self->{error} = undef; | ||
| 36 | my %param = ( | ||
| 37 | ip => Sys::Hostname::hostname, | ||
| 38 | port => 40101, | ||
| 39 | name => join('_'=>Sys::Hostname::hostname, ($0 =~ /(\w+)/g), $$), | ||
| 40 | %{$self->{create_ikc_client}}, | ||
| 41 | @_ | ||
| 42 | ); | ||
| 43 | $self->{ikc} = create_ikc_client(%param); | ||
| 44 | if (not($self->{ikc})) { | ||
| 45 | $self->{error} = $POE::Component::IKC::ClientLite::error; | ||
| 46 | $self->{RaiseError} and die($POE::Component::IKC::ClientLite::error); | ||
| 47 | } | ||
| 48 | return $self->{ikc}; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub privmsg { | ||
| 52 | my $self = shift; | ||
| 53 | $self->{error} = undef; | ||
| 54 | my $irc_conf_hash_ref = shift; | ||
| 55 | $self->{ikc} ||= $self->connect; | ||
| 56 | if ( $self->{ikc} ) { | ||
| 57 | my $ret = $self->{ikc}->post_respond( | ||
| 58 | 'IKC_IRC/message_respond' => [ | ||
| 59 | 'privmsg', | ||
| 60 | $irc_conf_hash_ref, | ||
| 61 | @_ | ||
| 62 | # {"channel"=>"#test","connect"=>{"Nick"=>"poeN","Username"=>"poeU","debug"=>1,"Port"=>6667,"flood"=>1,"Ircname"=>"localhost"}}, | ||
| 63 | # messages .. | ||
| 64 | ] | ||
| 65 | ); | ||
| 66 | return $ret; | ||
| 67 | } | ||
| 68 | return ; | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; | ||
| 72 | __END__ |