POE::Component::DirWatch's file_callback parameter requires a plain coderef. The coderef you are supplying is a POE type handler

Your found_file sub should probably be:

sub found_file { my $file = shift; warn "Found '$file'\n"; }

To do it a POE way would be to supply a postback or callback to POE::Component::DirWatch so it sends an event back to your session:

use warnings; use strict; use POE; use POE::Component::DirWatch; POE::Session->create( inline_states => { _start => \&init_watcher, watch_dir => \&watch_dir, found_file => \&found_file, }, ); sub init_watcher { my ($kernel, $heap, $session, $sender) = @_[KERNEL, HEAP, SESSION, +SENDER]; warn "Queue 1 starting (session id " . $session->ID . ")"; # watch a directory for this queue $kernel->yield('watch_dir', '/tmp/queue1'); } sub watch_dir { my ($kernel, $heap, $session, $queue) = @_[KERNEL, HEAP, SESSION, + ARG0]; # start watching the directory POE::Component::DirWatch->new( alias => 'dirwatch', directory => $queue, file_callback => $session->postback('foun +d_file'), interval => 1, ); } sub found_file { my ($kernel, $heap, $session, $sender, $args) = @_[KERNEL, HEAP, S +ESSION, SENDER, ARG1]; my $file = shift @{ $args }; # warn "Found '$file' for " . $session->ID . " (from " . $sender->I +D . ")\n"; warn "Found '$file' for $session->ID\n"; } $poe_kernel->run(); exit(0);

In reply to Re: Watching a directory with POE::Component::DirWatch by bingos
in thread Watching a directory with POE::Component::DirWatch by chanakya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.