Tk

 view release on metacpan or  search on metacpan

Event/Event/IO.pm  view on Meta::CPAN

 $obj->wait(READABLE);
 my $h = $obj->handle;
 my $w = <$h>;
 return $w;
}

sub READ
{
 my $obj = $_[0];
 $obj->wait(READABLE);
 my $h = $obj->handle;
 return sysread($h,$_[1],$_[2],defined $_[3] ? $_[3] : 0);
}

sub GETC
{
 my $obj = $_[0];
 $obj->wait(READABLE);
 my $h = $obj->handle;
 return getc($h);
}

sub CLOSE
{
 my $obj = shift;
 $obj->unwatch;
 my $h = $obj->handle;
 return close($h);
}

sub EOF
{
 my $obj = shift;
 my $h = $obj->handle;
 return eof($h);
}

sub FILENO
{
 my $obj = shift;
 my $h = $obj->handle;
 return fileno($h);
}

sub imode
{
 my $mode = shift;
 my $imode = ${{'readable' => READABLE(),
                'writable' => WRITABLE()}}{$mode};
 croak("Invalid handler type '$mode'") unless (defined $imode);
 return $imode;
}

sub fileevent
{
 my ($widget,$file,$mode,$cb) = @_;
 my $imode = imode($mode);
 unless (ref $file)
  {
   no strict 'refs';
   $file = Symbol::qualify($file,(caller)[0]);
   $file = \*{$file};
  }
 my $obj = tied(*$file);
 unless ($obj && $obj->isa('Tk::Event::IO'))
  {
   $obj = tie *$file,'Tk::Event::IO', $file;
  }
 if (@_ == 3)
  {
   # query return the handler
   return $obj->handler($imode);
  }
 else
  {
   # set the handler
   my $h = $obj->handler($imode,$cb);
   undef $obj;  # Prevent warnings about untie with ref to object
   unless ($h)
    {
     untie *$file;
    }
  }
}

1;
__END__



( run in 3.074 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )