Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1a17709292
Fetching contributors…

Cannot retrieve contributors at this time

file 49 lines (40 sloc) 1.171 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
package Reflex::Filehandle;
# vim: ts=2 sw=2 noexpandtab

use Moose;
extends 'Reflex::Base';
use Reflex::Callbacks qw(make_emitter);
use Carp qw(croak);

has descriptor => ( is => 'rw', isa => 'Maybe[Int]', default => undef );

has handle => (
  is => 'rw',
  isa => 'FileHandle',
  lazy => 1,
  default => sub {
    my $self = shift();
    my $fd = $self->descriptor();
    croak "Reflex::Filehandle must have a descriptor handle" unless (
      defined $fd
    );

    open my($fh), "+<&=$fd" or croak "can't dup fd $fd: $!";

    return $fh;
  }
);

has rd => ( is => 'ro', isa => 'Bool', default => 0 );
has wr => ( is => 'ro', isa => 'Bool', default => 0 );

with 'Reflex::Role::Readable' => {
  att_handle => 'handle',
  att_active => 'rd',
  cb_ready => make_emitter(on_readable => 'readable'),
  method_pause => 'pause_rd',
  method_resume => 'resume_rd',
  method_stop => 'stop_rd',
};

with 'Reflex::Role::Writable' => {
  att_handle => 'handle',
  att_active => 'wr',
  cb_ready => make_emitter(on_writable => 'writable'),
  method_pause => 'pause_wr',
  method_resume => 'resume_wr',
  method_stop => 'stop_wr',
};

1;
Something went wrong with that request. Please try again.