Devel::Events::Objects(3)

NAME
Devel::Events::Objects - Object tracking support for Devel::Events

SYNOPSIS
        use Devel::Cycle;
        use Data::Dumper;

        use Devel::Events::Handler::ObjectTracker;
        use Devel::Events::Filter::RemoveFields;
        use Devel::Events::Generator::Objects;

        my $tracker = Devel::Events::Handler::ObjectTracker->new();

        my $gen = Devel::Events::Generator::Objects->new(
                handler => Devel::Events::Filter::RemoveFields->new(
                        fields => [qw/generator/], # don't need to have a ref to $gen in each event
                        handler => $tracker,
                ),
        );

        $gen->enable(); # start generating events

        $code->(); # check for leaks in this code

        $gen->disable();

        # live_objects is a Tie::RefHash::Weak hash

        my @leaked_objects = keys %{ $tracker->live_objects };

        print "leaked ", scalar(@leaked_objects), " objects\n";

        foreach my $object ( @leaked_objects ) {
                print "Leaked object: $object\n";

                # the event that generated it
                print Dumper( $object, $tracker->live_objects->{$object} );

                find_cycle( $object );
        }

DESCRIPTION
This package provides an event generator and a handler for Devel::Events, that facilitate leak checking.

There are two components of this module: Devel::Events::Generator::Objects, and Devel::Events::Handler::ObjectTracker.

The first one uses some trickery to generate events for every object creation and destruction in code loaded after it was loaded.

The second one will listen on these events, and track all currently living objects.

See the "SYOPSIS" for how to write your own leak tracker, and Catalyst::Plugin::LeakTracker for a real world application of these classes.

SEE ALSO
Devel::Events, Devel::Events::Filter::Size, Catalyst::Plugin::LeakTracker, Devel::Cycle, Devel::Leak::Object

AUTHOR
Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT & LICENSE
        Copyright (c) 2007 Yuval Kogman. All rights reserved
        This program is free software; you can redistribute it and/or modify it
        under the terms of the MIT license or the same terms as Perl itself.