Devel-Cycle

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


1.08 Fri Apr 11 17:55:59 EDT 2008
     	- Peter Brakemeier identified and patched bug in which stringified objects could
           create false positives. Thanks Peter!

1.07 Tue May 23 22:28:03 EDT 2006
	- Fixed export_to_level() problem so that Test::Memory::Cycle works again.

1.06 Tue May 23 17:08:22 EDT 2006
	- Removed debugging warning.
	- Only checks CODErefs if PadWalker version >= 1.0.

1.05 May 18 2006
	- Added ability to detect cycles in CODErefs courtesy Yuval Kogman.

1.04
	- Added ability to detect weakened cycles courtesy Stevan Little

1.03 Fri Jan 21 13:47:50 EST 2005
	- Sort the hash keys so that the cycle path is more deterministic
	(avoids test failures in Test::Memory::Cycle)

lib/Devel/Cycle.pm  view on Meta::CPAN


my %import_args = (-quiet =>1,
		   -raw   =>1,
		   -cooked =>1,
		   -roasted=>1);

BEGIN {
  require constant;
  constant->import( HAVE_PADWALKER =>
		    eval {
		      require PadWalker;
		      $PadWalker::VERSION >= 1.0;
		    });
}

sub import {
  my $self = shift;
  my @args = @_;
  my %args = map {$_=>1} @args;
  $QUIET++    if exists $args{-quiet};
  $FORMATTING = 'roasted' if exists $args{-roasted};
  $FORMATTING = 'raw'     if exists $args{-raw};

lib/Devel/Cycle.pm  view on Meta::CPAN

sub _find_cycle_CODE {
  my $current   = shift;
  my $seenit    = shift;
  my $callback  = shift;
  my $inc_weak_refs = shift;
  my $complain  = shift;
  my @report  = @_;

  unless (HAVE_PADWALKER) {
    if (!$complain->{$current} && !$QUIET) {
      carp "A code closure was detected in but we cannot check it unless the PadWalker module is installed";
    }

    return;
  }

  my $closed_vars = PadWalker::closed_over( $current );
  foreach my $varname ( sort keys %$closed_vars ) {
    my $value = $closed_vars->{$varname};
    _find_cycle_dispatch($value,{%$seenit},$callback,$inc_weak_refs,$complain,
                         (@report,['CODE',$varname,$current => $value]));
  }
}

sub _do_report {
  my $counter = shift;
  my $path    = shift;

lib/Devel/Cycle.pm  view on Meta::CPAN

       $FORMATTING = 'raw';

Alternatively, you can control the formatting at compile time by
passing one of the options -raw, -cooked, or -roasted to "use" as
illustrated here:

  use Devel::Cycle -raw;

=head2 Code references (closures)

If the PadWalker module is installed, Devel::Cycle will also report
cycles in code closures. If PadWalker is not installed and
Devel::Cycle detects a CODE reference in one of the data structures,
it will warn (once per data structure) that it cannot inspect the CODE
unless PadWalker is available. You can turn this warning off by
passing -quiet to Devel::Cycle at compile time:

 use Devel::Cycle -quiet;

=head1 SEE ALSO

L<Test::Memory::Cycle>
L<Devel::Leak>
L<Scalar::Util>

t/Devel-Cycle.t  view on Meta::CPAN


my $a = bless {},'foo';
my $b = bless {},'bar';
$a->{'b'} = $b;
$counter = 0;
find_cycle($a,sub {$counter++});
is($counter,0,'found no cycles in reference stringified on purpose to create a false alarm');

SKIP:
{
    skip 'These tests require PadWalker 1.0+', 1
        unless Devel::Cycle::HAVE_PADWALKER;

    $counter = 0;

    my %cyclical = ( a => [],
                     b => {},
                   );
    $cyclical{a}[0]   = $cyclical{a};
    $cyclical{b}{key} = $cyclical{a};



( run in 0.605 second using v1.01-cache-2.11-cpan-05444aca049 )