File: | lib/Code/Statistics/Metric/sdepth.pm |
Coverage: | 100.0% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 2 2 2 | 0 0 0 | use strict; | ||||
2 | 2 2 2 | 0 0 0 | use warnings; | ||||
3 | |||||||
4 | package Code::Statistics::Metric::sdepth; | ||||||
5 | |||||||
6 | # ABSTRACT: measures the scope depth of a target | ||||||
7 | |||||||
8 | 2 2 2 | 0 0 0 | use Moose; | ||||
9 | extends 'Code::Statistics::Metric'; | ||||||
10 | |||||||
11 - 13 | =head2 measure Returns the scope depth of the given target. =cut | ||||||
14 | |||||||
15 | sub measure { | ||||||
16 | my ( $class, $target ) = @_; | ||||||
17 | |||||||
18 | my @parent_list = $class->_get_parents( $target ); | ||||||
19 | |||||||
20 | my $depth = @parent_list - 1; | ||||||
21 | |||||||
22 | return $depth; | ||||||
23 | } | ||||||
24 | |||||||
25 | sub _get_parents { | ||||||
26 | my ( $class, $target ) = @_; | ||||||
27 | my $parent = $target->parent; | ||||||
28 | return $target if !$parent; | ||||||
29 | return ( $target, $class->_get_parents( $parent ) ); | ||||||
30 | } | ||||||
31 | |||||||
32 | 1; |