Moose

 view release on metacpan or  search on metacpan

xt/author/memory_leaks.t  view on Meta::CPAN

        'making an anon class immutable is leak-free'
    );
}

{
    my $meta3 = Moose::Meta::Class->create('MyClass3');
    memory_cycle_ok( $meta3, 'named metaclass object is cycle-free' );
    memory_cycle_ok( $meta3->new_object, 'MyClass3 object is cycle-free' );

    my $anon_class = Moose::Meta::Class->create_anon_class;
    memory_cycle_ok($anon_class, 'anon metaclass object is cycle-free' );
    memory_cycle_ok( $anon_class->new_object, 'object from anon metaclass is cycle-free' );

    $anon_class->make_immutable;
    memory_cycle_ok($anon_class, 'immutable anon metaclass object is cycle-free' );
    memory_cycle_ok( $anon_class->new_object, 'object from immutable anon metaclass is cycle-free' );

    my $anon_role = Moose::Meta::Role->create_anon_role;
    memory_cycle_ok($anon_role, 'anon role meta object is cycle-free' );
}

{
    my $Str = find_type_constraint('Str');
    my $Undef = find_type_constraint('Undef');
    my $Str_or_Undef = Moose::Meta::TypeConstraint::Union->new(
        type_constraints => [ $Str, $Undef ] );
    memory_cycle_ok($Str_or_Undef, 'union types do not leak');
}

{
    my $mtg = Mortgage->new( closing_date => 'yesterday' );
    $mtg->closing_date;
    Mortgage->meta->make_immutable;

    memory_cycle_ok($mtg->meta, 'meta (triggers/coerce) is cycle-free');
}

{
    local $TODO = 'meta cycles exist at the moment';
    memory_cycle_ok(Earth->new->meta, 'meta (handles) is cycle-free');
    memory_cycle_ok(Earth->meta,      'meta (class) is cycle-free');
}

{
    my $Point = Class::MOP::Class->create('Point' => (
        version    => '0.01',
        attributes => [
            Class::MOP::Attribute->new('x' => (
                reader   => 'x',
                init_arg => 'x'
            )),
            Class::MOP::Attribute->new('y' => (
                accessor => 'y',
                init_arg => 'y'
            )),
        ],
        methods => {
            'new' => sub {
                my $class = shift;
                my $instance = $class->meta->new_object(@_);
                bless $instance => $class;
            },
            'clear' => sub {
                my $self = shift;
                $self->{'x'} = 0;
                $self->{'y'} = 0;
            }
        }
    ));

    my $Point3D = Class::MOP::Class->create('Point3D' => (
        version      => '0.01',
        superclasses => [ 'Point' ],
        attributes => [
            Class::MOP::Attribute->new('z' => (
                default  => 123
            )),
        ],
        methods => {
            'clear' => sub {
                my $self = shift;
                $self->{'z'} = 0;
                $self->SUPER::clear();
            }
        }
    ));

    local $TODO = 'CMOP cycles exist at the moment';
    memory_cycle_ok($Point3D,       'Point3D is cycle-free');
    memory_cycle_ok($Point,         'Point is cycle-free');
    memory_cycle_ok($Point3D->meta, 'Point3D meta is cycle-free');
    memory_cycle_ok($Point->meta,   'Point meta is cycle-free');
}

done_testing;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.902 second using v1.00-cache-2.02-grep-82fe00e-cpan-b63e86051f13 )