in reply to Re: Cyclomatic Complexity of Perl code
in thread Cyclomatic Complexity of Perl code

You don't co-opt B::Concise for this. You use B::Utils::walkoptree() and everywhere you find a B::LOGOP, you increment your complexity by one. You shouldn't actually use this, however, for points better raised by BrowserUK, simonm, and stvn in other parts of this thread.

use B (); use B::Utils (); print "function() == " . sub_simplistic_complexity( \ &function ); print "overall: " . program_simplistic_complexity(); sub program_simplistic_complexity { my $simplistic_complexity = 0; for my $op ( B::Utils::all_roots() ) { $simplistic_complexity += op_simplistic_complexity( $op ) } return $simplistic_complexity; } sub sub_simplistic_complexity { op_simplistic_complexity( B::svref_2object( shift() )->ROOT ); } sub op_simplistic_complexity { my $op = shift; my $simplistic_complexity = 0; B::Utils::walkoptree_filtered( $op, sub { shift() -> can( 'other' ) }, sub { ++ $simplistic_complexity } ); return $simplistic_complexity; }

Replies are listed 'Best First'.
Re^3: Cyclomatic Complexity of Perl code
by stvn (Monsignor) on Dec 08, 2004 at 20:50 UTC

    Could you elaborate on the signifagance of B::LOGOP please?

    -stvn
      It is the base for the "else" part of "if then else". I changed my logic to query about when ->other is available. That's the property associated with "else."