Author image Piotr Roszatycki


MooseX::GlobRef - Store a Moose object in glob reference


  package My::IO;

  use Moose;
  use MooseX::GlobRef;

  has 'file' => ( is => 'ro', isa => 'Str', required => 1 );

  sub open {
    my $fh = shift;
    open $fh, $fh->file or confess "cannot open";
    return $fh;

  sub getlines {
    my $fh = shift;
    return readline $fh;

  my $io = My::IO->new( file => '/etc/passwd' );
  print "::::::::::::::\n";
  print $io->file, "\n";
  print "::::::::::::::\n";
  print $io->getlines;


This module allows to store Moose object in glob reference of file handle. The class attributes will be stored in hash slot associated with glob reference. It allows to create a Moose version of IO::Handle.

The attributes can be accessed directly with following expression:

  my $hashref = \%{*$self};
  print $hashref->{key};

or shorter:

  print *$self->{key};

but the standard accessors should be used instead:

  print $self->key;


init_meta( args : Hash ) : Moose::Meta::Class

See Moose::Exporter.

SEE ALSO, Moose.


Piotr Roszatycki <>


Copyright (c) 2007, 2008, 2009, 2010 Piotr Roszatycki <>.

This is free software; you can redistribute it and/or modify it under the same terms as perl itself.