1MooseX::GlobRef(3) User Contributed Perl Documentation MooseX::GlobRef(3)
2
3
4
6 MooseX::GlobRef - Store a Moose object in glob reference
7
9 package My::IO;
10
11 use Moose;
12 use MooseX::GlobRef;
13
14 has 'file' => ( is => 'ro', isa => 'Str', required => 1 );
15
16 sub open {
17 my $fh = shift;
18 open $fh, $fh->file or confess "cannot open";
19 return $fh;
20 }
21
22 sub getlines {
23 my $fh = shift;
24 return readline $fh;
25 }
26
27 my $io = My::IO->new( file => '/etc/passwd' );
28 print "::::::::::::::\n";
29 print $io->file, "\n";
30 print "::::::::::::::\n";
31 $io->open;
32 print $io->getlines;
33
35 This module allows to store Moose object in glob reference of file
36 handle. The class attributes will be stored in hash slot associated
37 with glob reference. It allows to create a Moose version of
38 IO::Handle.
39
40 The attributes can be accessed directly with following expression:
41
42 my $hashref = \%{*$self};
43 print $hashref->{key};
44
45 or shorter:
46
47 print *$self->{key};
48
49 but the standard accessors should be used instead:
50
51 print $self->key;
52
54 init_meta( args : Hash ) : Moose::Meta::Class
55 See Moose::Exporter.
56
58 <http://github.com/dex4er/perl-MooseX-GlobRef>, Moose.
59
61 Piotr Roszatycki <dexter@cpan.org>
62
64 Copyright (c) 2007, 2008, 2009, 2010 Piotr Roszatycki
65 <dexter@cpan.org>.
66
67 This is free software; you can redistribute it and/or modify it under
68 the same terms as perl itself.
69
70 See <http://dev.perl.org/licenses/artistic.html>
71
72
73
74perl v5.30.1 2020-01-30 MooseX::GlobRef(3)