Skip Menu |

This queue is for tickets about the POE-Component-Client-MPD CPAN distribution.

Report information
The Basics
Id: 39408
Status: resolved
Priority: 0/
Queue: POE-Component-Client-MPD

People
Owner: jquelin [...] cpan.org
Requestors: andrew [...] etc.gen.nz
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.9.0
Fixed in: (no value)



Subject: Fails to compile
I'm trying to make a new POCOCM instance, but I'm getting the following error: Can't locate object method "put" via package "POE::Wheel::SocketFactory" at /usr/share/perl5/POE/Component/Client/MPD/Connection.pm line 216. I'm using code very similar to what you've given in the man page, I'm using: use POE::Component::Client::MPD; POE::Component::Client::MPD->spawn( { alias => 'mpd' } ); Can you shed any light on this? Cheers!
i'm missing some context here. - are we talking pococm 0.9.0? - what is your poe version? - where is your mpd located, localhost? - can you attach the faulty program? this kind of error seems to come when one tries to send commands when the pococm is not yet connected to mpd. if that is the case: - i intend to put some checks for this later on. - you can spawn pococm with option status_msgs_to => $session with $session your own session. and then don't send anything unless you've received the mpd_connected event. (this needs to be documented)
From: andrew [...] etc.gen.nz
On Fri Sep 19 04:55:45 2008, JQUELIN wrote: Show quoted text
> i'm missing some context here. > - are we talking pococm 0.9.0?
Yes Show quoted text
> - what is your poe version?
1.0003 Show quoted text
> - where is your mpd located, localhost?
Localhost Show quoted text
> - can you attach the faulty program?
It is a plugin for part of a Clutter app, I'm writing. I've attached the module that is doing it. Interestingly enough it works okay on another where the mpd daemon is on a remote computer. Show quoted text
> this kind of error seems to come when one tries to send commands when > the pococm is not yet connected to mpd. > > if that is the case: > - i intend to put some checks for this later on. > - you can spawn pococm with option > status_msgs_to => $session > with $session your own session. and then don't send anything unless > you've received the mpd_connected event. (this needs to be documented)
Okay, I've added in the status_msgs_to event (as you can see in the attachment) but it still isn't working. Cheers!
package Display::Plugins::MPD; use Clutter; use POSIX qw/strftime/; use base ('Display::Plugin'); use POE qw{ Component::Client::MPD }; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(@_); $self->{'file'} = ''; $self->{'active'} = 0; bless ($self, $class); $self->init(); return $self; } sub display { my ($self, $msg, $answer) = @_[OBJECT, ARG0, ARG1]; warn "Got a response from MPD\n"; my $current = $answer->current(); if ($self->{'file'} ne $current->file()) { my @lines = (); push @lines, $current->title() if defined $current->title(); push @lines, $current->album() if defined $current->album(); push @lines, $current->artist() if defined $current->artist(); $self->{'status'}->set_text(join("\n", @lines)); $self->{'file'} = $current->file(); $self->{'bg'}->set_height($self->{'status'}->get_height() + 10); $self->{'bg'}->set_anchor_point(1, $self->{'bg'}->get_height()); $self->{'bg'}->set_position(10, $self->{'stage'}->get_height() - 10); $self->{'status'}->set_anchor_point(1, $self->{'status'}->get_height()); $self->{'status'}->set_position(15, $self->{'stage'}->get_height() - 20); if (! $self->{'active'}) { $self->{'stage'}->add($self->{'bg'}); $self->{'stage'}->add($self->{'status'}); $self->{'active'} = time() + 30; } $self->{'KERNEL'}->delay( hide_display, 30 ); } $self->{'KERNEL'}->delay( mpd, 5, current ); } sub hide_display { my $self = shift; if ($self->{'active'} <= time()) { $self->{'stage'}->remove($self->{'status'}); $self->{'stage'}->remove($self->{'bg'}); $self->{'active'} = 0; } return 0; } sub error { my ($kernel, $msg, $errstr) = @_[KERNEL, ARG0, ARG1]; warn "MPD: Error $errstr\n"; $kernel->delay( mpd, 5, current ); } sub init { my $self = shift; $self->{'kernel'}->state('mpd_result', $self, 'display'); $self->{'kernel'}->state('mpd_error', $self, 'error'); $self->{'kernel'}->state('mpd_hide_display', $self, 'hide_display'); POE::Component::Client::MPD->new( { alias => 'mpd', status_msgs_to => 'mpd_status_msgs', } ); $self->{'status'} = Clutter::Label->new('Sans 20', "Song\nAlbum"); $self->{'status'}->set_color(Clutter::Color->parse('White')); $self->{'bg'} = Clutter::Rectangle->new(Clutter::Color->parse('Black')); $self->{'bg'}->set_width($self->{'stage'}->get_width() - 40); $self->{'bg'}->set_opacity(100); } sub mpd_status_msgs { my ($kernel, $arg) = @_[KERNEL, ARG0]; if ($arg eq 'mpd_connected') { $self->{'kernel'}->post( 'mpd', 'current' ); } else { warn "Failed to connected to MPD. What now?\n"; } } 1;
uh, you misunderstood me. status_msgs_to is *not* an event, it's a parameter telling the pococm which session to send status events to. ie, if your poe session (*your* poe session, not the pococm) is aliased to 'clutter' or 'display', then you should call the pococm with: POE::Component::Client::MPD->spawn({alias=>'mpd', status_msgs_to=>'clutter'}); when this is done, pococm will send *additional* events [0] to 'clutter' such as: - 'mpd_connected' when pococm is connected, - 'mpd_disconnected' when pococm is disconnected, - etc. then, you need to register some handlers for those events, and make sure you don't fire any event when pococm is disconnected[1]. i could reliably reproduce your problem with the following scripts: #!/usr/bin/perl use POE qw{ Component::Client::MPD }; my $alias = 'foo'; POE::Component::Client::MPD->spawn({alias=>'mpd'}); POE::Session->create( inline_states => { _start => \&_start, _stop => sub { print "die\n"; }, } ); POE::Kernel->run; exit; sub _start { $poe_kernel->alias_set($alias); $poe_kernel->post( 'mpd', 'current' ); } ==> this example will produce a 'Can't locate object method "put"...' but now take this one: #!/usr/bin/perl use POE qw{ Component::Client::MPD }; my $me = 'foo'; POE::Component::Client::MPD->spawn({alias=>'mpd', status_msgs_to=>$me}); POE::Session->create( inline_states => { _start => \&_start, _stop => sub { print "die\n"; }, mpd_connected => \&mpd_connected, mpd_result => \&mpd_result, } ); POE::Kernel->run; exit; sub _start { $poe_kernel->alias_set($me); } sub mpd_connected { $poe_kernel->post( 'mpd', 'current' ); } sub mpd_result { use Data::Dumper; print Dumper($_[ARG1]); } ==> this time, note that we're waiting for mpd_connected event before firing the event 'current'. and in this case, it works correctly... [0] this needs to be documented [1] future versions of pococm will take care of this, and: - check that pococm is connected - send errors when trying to send a command while not connected but i'm currently working on another module, so i don't have that much time for pococm. i guess i'll have some time later on, and complete it.
From: andrew [...] etc.gen.nz
On Mon Sep 22 12:44:56 2008, JQUELIN wrote: Show quoted text
> uh, you misunderstood me. > > status_msgs_to is *not* an event, it's a parameter telling the pococm > which session to send status events to. ie, if your poe session (*your* > poe session, not the pococm) is aliased to 'clutter' or 'display', then > you should call the pococm with:
Ahhhh... Right then. Show quoted text
> but now take this one: > #!/usr/bin/perl > use POE qw{ Component::Client::MPD }; > my $me = 'foo';
[snip] Unfortunately this example doesn't rone for me, I get: Can't locate object method "date" via package "Audio::MPD::Common::Item::Song" at /usr/share/perl5/POE/Component/Client/MPD/Connection.pm line 112. I'm using Audio::MPD 0.19.4, is a newer version required? Show quoted text
> ==> this time, note that we're waiting for mpd_connected event before > firing the event 'current'. and in this case, it works correctly... > > [0] this needs to be documented
Documenting this better would be brilliant. Show quoted text
> [1] future versions of pococm will take care of this, and: > - check that pococm is connected > - send errors when trying to send a command while not connected
:) Show quoted text
> but i'm currently working on another module, so i don't have that much > time for pococm. i guess i'll have some time later on, and complete it.
I can understand that!
all common structures between audio::mpd and pococm are now in their own distrib audio::mpd::common. so you don't need to install audio::mpd to use pococm - you need audio::mpd::common. that said, audio::mpd::common::song is missing some fields, namely date in your case. i've opened a new ticket against audio::mpd::common, see http://rt.cpan.org/Ticket/Display.html?id=39529 therefore, closing this bug.