Re: PerlMagick and Moo

[email protected] (Rick Leir) Tue, 21 Jul 2015 08:50:03 -0400
Newsgroups perl.moose
Message-ID <CAGitpvbrpWq2ptdqo-vX-NeS4UXE+KUJtumNVN459k0-FB-RoA@mail.gmail.com>
--001a113b530cc62f17051b621721
Content-Type: text/plain; charset=UTF-8

On Mon, Jul 20, 2015 at 5:13 PM, Kent Fredric <[email protected]> wrote:

> On 21 July 2015 at 03:35, Rick Leir <[email protected]> wrote:
> > My question is how can you delete all the images but retain the
> > Graphics::Magick object? I do not want to use the undef loop above. With
> > normal perlmagick, you would say
> >   @$image = ();
> > ( http://www.graphicsmagick.org/perl.html )
> >
> > Should I learn more about Perl XS?  TIA
>
>
> Q) What value is there in persisting the GM object across uses? Why do
> you need to do this?
>
This is for a web service, so I want to reduce latency by keeping the GM
object. We get at it using 'instance', not 'new'. And reclaiming image
memory is important.


>
> Without good reason, I would take the advice in the Linked article,
> and just `undef` the GM object.
>
> The natural way of doing this in Moo would be to use a clearer
>
> https://metacpan.org/pod/Moo#has
>
> #{
>
> Takes a method name which will clear the attribute.
>
> If you set this to just 1, the clearer is automatically named
> clear_${attr_name} if your attribute's name does not start with an
> underscore, or _clear_${attr_name_without_the_underscore} if it does.
> This feature comes from MooseX::AttributeShortcuts.
>
> #}
>
> That way, when you're done, you just call
>
>  $self->_clear_image;
>
> And if you need an image later, a new one will be constructed by the
> builder.
>
Thanks for explaining 'clearer'.
cheers -- Rick

>
> --
> Kent
>
> KENTNL - https://metacpan.org/author/KENTNL
>



-- 
Rick Leir
Developer, Canadiana.ca

--001a113b530cc62f17051b621721
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On M=
on, Jul 20, 2015 at 5:13 PM, Kent Fredric <span dir=3D"ltr">&lt;<a href=3D"=
mailto:[email protected]" target=3D"_blank">[email protected]</a>&g=
t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=3D"">On 21 J=
uly 2015 at 03:35, Rick Leir &lt;<a href=3D"mailto:[email protected]=
a">[email protected]</a>&gt; wrote:<br>
&gt; My question is how can you delete all the images but retain the<br>
&gt; Graphics::Magick object? I do not want to use the undef loop above. Wi=
th<br>
&gt; normal perlmagick, you would say<br>
&gt;=C2=A0 =C2=A0@$image =3D ();<br>
</span>&gt; ( <a href=3D"http://www.graphicsmagick.org/perl.html" rel=3D"no=
referrer" target=3D"_blank">http://www.graphicsmagick.org/perl.html</a> )<b=
r>
<span class=3D"">&gt;<br>
&gt; Should I learn more about Perl XS?=C2=A0 TIA<br>
<br>
<br>
</span>Q) What value is there in persisting the GM object across uses? Why =
do<br>
you need to do this?<br></blockquote><div>This is for a web service, so I w=
ant to reduce latency by keeping the GM object. We get at it using &#39;ins=
tance&#39;, not &#39;new&#39;. And reclaiming image memory is important.<br=
>=C2=A0<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Without good reason, I would take the advice in the Linked article,<br>
and just `undef` the GM object.<br>
<br>
The natural way of doing this in Moo would be to use a clearer<br>
<br>
<a href=3D"https://metacpan.org/pod/Moo#has" rel=3D"noreferrer" target=3D"_=
blank">https://metacpan.org/pod/Moo#has</a><br>
<br>
#{<br>
<br>
Takes a method name which will clear the attribute.<br>
<br>
If you set this to just 1, the clearer is automatically named<br>
clear_${attr_name} if your attribute&#39;s name does not start with an<br>
underscore, or _clear_${attr_name_without_the_underscore} if it does.<br>
This feature comes from MooseX::AttributeShortcuts.<br>
<br>
#}<br>
<br>
That way, when you&#39;re done, you just call<br>
<br>
=C2=A0$self-&gt;_clear_image;<br>
<br>
And if you need an image later, a new one will be constructed by the builde=
r.<br></blockquote><div>Thanks for explaining &#39;clearer&#39;.<br></div><=
div>cheers -- Rick<br></div><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=3D"H=
OEnZb"><font color=3D"#888888">
<br>
--<br>
Kent<br>
<br>
KENTNL - <a href=3D"https://metacpan.org/author/KENTNL" rel=3D"noreferrer" =
target=3D"_blank">https://metacpan.org/author/KENTNL</a><br>
</font></span></blockquote></div><br><br clear=3D"all"><br>-- <br><div clas=
s=3D"gmail_signature"><div dir=3D"ltr">Rick Leir<br>Developer, Canadiana.ca=
<br></div></div>
</div></div>

--001a113b530cc62f17051b621721--