[Catalyst] Working with references to large scalars

Simon Miner sminer at christianbook.com
Mon Aug 29 16:45:30 CEST 2005


Hi,

 

I need my controller to do some post-processing on the content generated
by my app's view component.  Right now, I've got some code in my
controller that looks something like this...

 

    my $output = $c->res->output;

    my $html_ref = post_process( \$output );

    $c->res->output( $$html_ref );

 

The content is typically fairly large (many times > 100K), so that's why
the post_process() function takes and returns references to scalars.  I
would like to apply this use of references to the code that gets and
sets $c->res->output so that I can avoid copying the large scalar
values.

 

I've figured out that I can say this instead...

 

    my $body_ref = \$c->res->{body};

    my $html_ref = post_process( $body_ref );

    $c->res->output( $$html_ref );

 

This takes care of the "get" case, but it bypasses the OO encapsulation
set up by Class::Accessor. If there's a better way to do this, I'd be
interested to hear about it.  My main question, however, is how to make
the statement which sets $c->res->output use references.  Essentially,
I'd like to change the location in memory referred to by
$c->res->{body}, like so.

 

\$c->res->{body} = $html_ref;

 

But Perl doesn't like this ("Can't modify single ref constructor in
scalar assignment").

 

Any ideas on how to do this (preferably without bypassing the OO
encapsulation)?

 

Thanks,

 

- Simon

-----------------------------------------------

Simon Miner

Applications Engineer

Christianbook.com

E: sminer at christianbook.com <mailto:sminer at christianbook.com> 

T: (978) 573-2233

F: (978) 573-8233

-----------------------------------------------

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20050829/a808c012/attachment.htm


More information about the Catalyst mailing list