minor edits for 0.02 dist
[gitmo/Algorithm-C3.git] / lib / Algorithm / C3.pm
index 064e935..d4c49e3 100644 (file)
@@ -6,18 +6,7 @@ use warnings;
 
 use Carp 'confess';
 
-our $VERSION = '0.01';
-
-sub _fetcher {
-    my ($root, $_parent_fetcher) = @_;
-
-    my $parent_fetcher = $_parent_fetcher;
-    unless (ref($parent_fetcher) && ref($parent_fetcher) eq 'CODE') {
-        $parent_fetcher = $root->can($_parent_fetcher)
-            || confess "Could not find method $_parent_fetcher in $root";
-    }
-    [ $parent_fetcher->($root) ];
-}
+our $VERSION = '0.02';
 
 sub merge {
     my ($root, $parent_fetcher) = @_;
@@ -26,8 +15,14 @@ sub merge {
     my %fcache; # cache of _fetcher results
     my %mcache; # cache of merge do-block results
 
+    my $pfetcher_is_coderef = ref($parent_fetcher) eq 'CODE';
+
+    unless ($pfetcher_is_coderef or $root->can($parent_fetcher)) {
+        confess "Could not find method $parent_fetcher in $root";
+    }
+
     my $current_root = $root;
-    my $current_parents = $fcache{$root} ||= _fetcher($root, $parent_fetcher);
+    my $current_parents = [ $root->$parent_fetcher ];
     my $recurse_mergeout = [];
     my $i = 0;
 
@@ -35,6 +30,10 @@ sub merge {
         if($i < @$current_parents) {
             my $new_root = $current_parents->[$i++];
 
+            unless ($pfetcher_is_coderef or $new_root->can($parent_fetcher)) {
+                confess "Could not find method $parent_fetcher in $new_root";
+            }
+
             push(@STACK, [
                 $current_root,
                 $current_parents,
@@ -43,8 +42,7 @@ sub merge {
             ]);
 
             $current_root = $new_root;
-            $current_parents = $fcache{$current_root}
-                ||= _fetcher($current_root, $parent_fetcher);
+            $current_parents = $fcache{$current_root} ||= [ $current_root->$parent_fetcher ];
             $recurse_mergeout = [];
             $i = 0;
             next;
@@ -226,9 +224,9 @@ is the B<Devel::Cover> report on this module's test suite.
  ------------------------ ------ ------ ------ ------ ------ ------ ------
  File                       stmt   bran   cond    sub    pod   time  total
  ------------------------ ------ ------ ------ ------ ------ ------ ------
- Algorithm/C3.pm           100.0  100.0   55.6  100.0  100.0  100.0   94.4
+ Algorithm/C3.pm           100.0  100.0  100.0  100.0  100.0  100.0  100.0
  ------------------------ ------ ------ ------ ------ ------ ------ ------
- Total                     100.0  100.0   55.6  100.0  100.0  100.0   94.4
+ Total                     100.0  100.0  100.0  100.0  100.0  100.0  100.0
  ------------------------ ------ ------ ------ ------ ------ ------ ------
 
 =head1 SEE ALSO
@@ -277,10 +275,12 @@ is the B<Devel::Cover> report on this module's test suite.
 
 =back 
 
-=head1 AUTHOR
+=head1 AUTHORS
 
 Stevan Little, E<lt>stevan@iinteractive.comE<gt>
 
+Brandon L. Black, E<lt>blblack@gmail.comE<gt>
+
 =head1 COPYRIGHT AND LICENSE
 
 Copyright 2006 by Infinity Interactive, Inc.