The following is an excerpt from some code that I'm experimenting with:

```
has buffer     => ( is => 'rw', isa => 'ScalarRef' );
has old_stdout => ( is => 'rw', isa => 'FileHandle' );

sub capture {
    my $self = shift;
    my $old_stdout;
    my $buffer;

    open $old_stdout, '>&', STDOUT
        or croak 'Cannot duplicate filehandle';

    close STDOUT;

    open STDOUT, '>', \$buffer
        or croak 'Cannot open filehandle';

    $self->old_stdout( $old_stdout );
    $self->buffer( \$buffer );
}

sub reset {
    my $self = shift;

    open STDOUT, '>&', $self->old_stdout
        or croak 'Cannot reset STDOUT';
}

```

Elsewhere:

```
my $stdout = Capture->new();
print "Some output\n";
$stdout->reset();

print $stdout->buffer();
# SCALAR(0x#######)

print ${$stdout->buffer()};
# Some output

```

I have tried cheating by setting the attribute hashref directly -- it works, but I don't like doing it:

```
    open STDOUT, '>', \$self->{buffer}
        or croak 'Cannot open filehandle';

```

I think I am missing something fundamental here. How should I go about storing `$buffer` (an in-memory file) as a Moose attribute, so that I can retrieve it later without the caller having to dereference it?

**Update**

I've added an `around` method modifier, which does the trick:

```
around 'buffer' => sub {
    my $orig = shift;
    my $self = shift;
    return ${$self->$orig} unless @_;
    $self->$orig( @_ );
};

```

...but it still feels messy. Is there a better way?