Grokbase
x

Ovid (publiustemp-cat...@yahoo.com)

Profile | Posts (2)

User Information

Display Name:Ovid
Partial Email Address:publiustemp-cat...@yahoo.com
Posts:
2 total
2 in Catalyst Framework

5 Most Recent

1) Ovid Moose Leaking?
| +1 vote
While writing some code to track down a memory leak, I came up with the fol= lowing program using...
Moose
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
While writing some code to track down a memory leak, I came up with the fol=
lowing program using Moose 0.93. It appears to show a few leaks:=0A=0A    #=
!/usr/bin/env perl=0A=0A    use Modern::Perl;=0A    use Devel::LeakGuard::O=
bject qw( GLOBAL_bless );=0A    use Devel::LeakGuard::Object::State;=0A=0A =
   my $leakstate;=0A=0A    BEGIN {=0A      $leakstate =3D Devel::LeakGuard:=
:Object::State->new(=0A on_leak =3D> sub {=0A my $report =
=3D shift;=0A my @leaks =3D sort { $b->[1] <=3D> $a->[1] } # hi=
gh refcount first=0A map { [ $_ =3D> $report->{$_}[1] ] } # c=
lass, refcount=0A            keys %$report;=0A          printf  "%-45s %s\n=
" =3D> qw/Class Refcount/;=0A          say "-" x 54;=0A=0A          foreach=
 my $leak (@leaks) {=0A            printf "%-50s %d\n" =3D> @$leak;=0A     =
     }=0A        }=0A      );=0A    }=0A    {=0A      package Foo;=0A      =
use Moose;=0A has me =3D> ( is =3D> 'rw' );=0A }=0A {=0A pa=
ckage Bar;=0A use Moose;=0A has me =3D> ( is =3D> 'rw' );=0A }=
=0A    {=0A=0A      package Baz;=0A      sub new { bless {} =3D> shift }=0A=
}=0A my $foo =3D Foo->new;=0A $foo->me($foo);=0A my $bar =3D B=
ar->new;=0A $bar->me($bar);=0A my $baz =3D Baz->new;=0A=0AAnd the out=
put:=0A=0A    Class                                         Refcount=0A    =
------------------------------------------------------=0A    Class::MOP::Me=
thod::Accessor                       221=0A    Class::MOP::Attribute       =
                       112=0A    Class::MOP::Method                        =
         48=0A    Class::MOP::Class::Immutable::Class::MOP::Class    43=0A =
   Class::MOP::Instance                               32=0A    Class::MOP::=
Method::Constructor                    30=0A    Moose::Meta::TypeConstraint=
                        19=0A    Class::MOP::Method::Wrapped               =
         17=0A    Class::MOP::Class                                  8=0A  =
  Moose::Meta::Method::Accessor                      4=0A    Moose::Meta::T=
ypeConstraint::Parameterizable       3=0A    Moose::Meta::Class            =
                     3=0A    Moose::Meta::Attribute                        =
     3=0A    Class::MOP::Package                                2=0A    Moo=
se::Meta::TypeConstraint::Class                 2=0A    Moose::Meta::Instan=
ce                              2=0A    Bar                                =
                1=0A    Config                                             =
1=0A    Baz                                                1=0A    Moose::M=
eta::TypeConstraint::Registry              1=0A    Foo                     =
                           1=0A=0AOur actual application has some of those =
refcounts in the thousands (it gets fun when I throw Catalyst and DBIx::Cla=
ss into the mix).  Am I just misunderstanding this output or does Moose lea=
k and Class::MOP leak?  (I'm suspicious because it shows that Baz still has=
 a refcount of one).=0A=0ACheers,=0AOvid=0A--=0ABuy the book         - http=
://www.oreilly.com/catalog/perlhks/=0ATech blog - http://use.per=
l.org/~Ovid/journal/=0ATwitter - http://twitter.com/OvidPerl=
=0AOfficial Perl 6 Wiki - http://www.perlfoundation.org/perl6
2) Ovid Re: MooseX::Role::Strict + MooseX::Role::Parameterized
| +1 vote
I haven't tried it, but have you tried this? package Force::Strict::Roles; use...
Moose
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
--- On Tue, 5/1/10, Karen Etheridge <perl@froods.org> wrote:

> From: Karen Etheridge <perl@froods.org>

> What would it take to gain the properties of
> MooseX::Role::Strict in
> MooseX::Role::Parameterized?  I've been using strict
> roles everywhere and
> love them -- they've caught a few bugs that I'm sure would
> have been
> dreadful to track down otherwise; now I'm parameterizing a
> few of my roles
> and I'm mourning the loss of strict checking.
>
> I've been meaning to find the time to just sit down and do
> some experiments
> myself (I've done a bit of meta hacking with traits and
> Moose::Exporter),
> but I'd like to toss the question out there in case anyone
> else has thought
> along similar lines.

I haven't tried it, but have you tried this?

  package Force::Strict::Roles;
  use MooseX::Strict::Role;
  1;

And then in your parameterized role:

  package SOme::Param::Role;
  use MooseX::Role::Parameterized;
  with 'Force::Strict::Roles';
  ...

???

Again, that's not tested, but it might work for you.

That being said, I need to write MooseX::Role::Warning. That's less safe, but it scales better for roles released to the CPAN.

Cheers,
Ovid
3) Ovid xor attributes
| +1 vote
I have two attributes, 'xml' and 'xml_file' for an object. One or the othe= r must be supplied, but...
Moose
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
I have two attributes, 'xml' and 'xml_file' for an object.  One or the othe=
r must be supplied, but not both.=0A=0AMust I validated this in BUILD or is=
 there another way of doing this?=0A=0ACheers,=0AOvid=0A--=0ABuy the book  =
- http://www.oreilly.com/catalog/perlhks/=0ATech blog - h=
ttp://use.perl.org/~Ovid/journal/=0ATwitter - http://twitter.c=
om/OvidPerl=0AOfficial Perl 6 Wiki - http://www.perlfoundation.org/perl6
4) Ovid Re: Triggers on inherited attributes
| +1 vote
----- Original Message ----=0A=0A> From: Jesse Luehrs <doy@tozt.net>=0A> > = That's a runtime bug...
Moose
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
----- Original Message ----=0A=0A> From: Jesse Luehrs <doy@tozt.net>=0A> > =
That's a runtime bug which probably shouldn't be there, but Moose doesn't =
=0A> really have a way of detecting that.  Being able to change your 'isa' =
is =0A> arguably worse than being able to add a trigger :)=0A> =0A> What's =
the issue here? This dies for me, saying that '2' isn't a valid=0A> Bool, w=
hich is what i'd expect it to do.=0A=0AYes, but changing the parent attribu=
te of 'Int' to a 'Bool'? That doesn't make sense, and thus, changing 'isa' =
is a bit dodgy.  That could have been a composition-time error, but allowin=
g the change to isa makes it a runtime-error.=0A=0A =0A(I'm not arguing for=
being more restrictive here, though. I suspect this would break a ton of c=
ode :)=0A=0ACheers,=0AOvid=0A--=0ABuy the book - http://www.oreilly=
..com/catalog/perlhks/=0ATech blog - http://use.perl.org/~Ovid/jo=
urnal/=0ATwitter - http://twitter.com/OvidPerl=0AOfficial Perl=
6 Wiki - http://www.perlfoundation.org/perl6
5) Ovid Re: Triggers on inherited attributes
| +1 vote
----- Original Message ----=0A=0A> From: Jesse Luehrs <doy@tozt.net>=0A=0A>= Hmmm, maybe we need a...
Moose
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
----- Original Message ----=0A=0A> From: Jesse Luehrs <doy@tozt.net>=0A=0A>=
Hmmm, maybe we need a more intelligent check then. I do think that=0A> ove=
rwriting an existing accessor like this shouldn't be allowed... it=0A> impl=
ies functionality that really isn't possible.=0A=0AWell, Moose already allo=
ws some pretty dubious things with accessors.  Consider the following:=0A=
=0A    {=0A        package One;=0A        use Moose;=0A=0A        has count=
er =3D> ( is =3D> 'rw', isa =3D> 'Int', default =3D> 1 );=0A=0A sub =
inc_counter {=0A            my $self =3D shift;=0A            $self->counte=
r( $self->counter + 1 );=0A        }=0A    }=0A    {=0A        package Two;=
=0A        use Moose;=0A        extends 'One';=0A        has '+counter' =3D=
> ( isa =3D> 'Bool' );=0A }=0A my $two =3D Two->new;=0A say $two->=
counter;=0A    $two->inc_counter;=0A=0AThat's a runtime bug which probably =
shouldn't be there, but Moose doesn't really have a way of detecting that. =
Being able to change your 'isa' is arguably worse than being able to add a=
trigger :)=0A=0A =0ACheers,=0AOvid=0A--=0ABuy the book - http://ww=
w.oreilly.com/catalog/perlhks/=0ATech blog - http://use.perl.org=
/~Ovid/journal/=0ATwitter - http://twitter.com/OvidPerl=0AOffi=
cial Perl 6 Wiki - http://www.perlfoundation.org/perl6

spacer
Profile | Posts (2)
Home > People > Ovid