File Coverage

blib/lib/Goo/Thing/pm/ThereDocManager.pm
Criterion Covered Total %
statement 21 45 46.6
branch 0 16 0.0
condition 0 3 0.0
subroutine 7 9 77.7
pod 2 2 100.0
total 30 75 40.0


line stmt bran cond sub pod time code
1             package Goo::Thing::pm::ThereDocManager;
2              
3             ###############################################################################
4             # Nigel Hamilton
5             #
6             # Copyright Nigel Hamilton 2005
7             # All Rights Reserved
8             #
9             # Author: Nigel Hamilton
10             # Filename: Goo::Thing::pm::ThereDocManager.pm
11             # Description: Process ThereDocs embedded in Things
12             #
13             # Date Change
14             # -----------------------------------------------------------------------------
15             # 16/08/2005 Auto generated file
16             # 16/08/2005 Needed a way to jump from Here to There
17             # 23/10/2005 Created test file: ThereDocManagerTest.tpm
18             #
19             ###############################################################################
20              
21 1     1   8617 use strict;
  1         3  
  1         46  
22              
23 1     1   8 use Goo::Loader;
  1         2  
  1         27  
24 1     1   5 use Goo::Prompter;
  1         2  
  1         24  
25 1     1   5 use Goo::ThereDocManager;
  1         2  
  1         24  
26 1     1   6 use Goo::Thing::pm::ScopeMatcher;
  1         3  
  1         24  
27 1     1   6 use Goo::Thing::pm::MethodMatcher;
  1         2  
  1         30  
28              
29 1     1   6 use base qw(Goo::ThereDocManager);
  1         3  
  1         525  
30              
31              
32             ###############################################################################
33             #
34             # find_package_and_method - return the method and package the there_doc is targetting
35             #
36             ###############################################################################
37              
38             sub find_package_and_method {
39              
40 0     0 1   my ($this, $target, $filename, $full_path, $target_line_number) = @_;
41              
42             # a simple method call in this package
43 0 0         if ($target =~ /\s+(\w+)\(/) {
44              
45             # package, method
46 0           return ($filename, $1);
47             }
48              
49             # a sub call in another package (e.g., Database::get_row())
50 0 0         if ($target =~ /(\w+)::(\w+)\(/) {
51              
52             # package, method
53 0           return ($1 . ".pm", $2);
54             }
55              
56             # a constructor call
57 0 0         if ($target =~ /(\w+)\->(new)\(/) {
58              
59             # package, method
60 0           return ($1 . ".pm", $2);
61             }
62              
63             # a method call
64 0 0         if ($target =~ /(\w+)\->(\w+)\(/) {
65              
66 0           my $referent = $1;
67 0           my $method = $2;
68              
69             # package, method
70 0 0         return ($filename, $method) if ($referent =~ /\$(this|self)/);
71              
72             # where is the referent from?
73             # look for it in the current scope
74 0           my $current_scope =
75             Goo::Thing::pm::ScopeMatcher::get_scope_of_line($target_line_number, $full_path);
76              
77             # For example, what is the package for $car?
78             # my $car = Car->new()
79 0 0         if ($current_scope =~ /my\s+\$$referent\s+=\s+(\w+)\->new\(/) {
80              
81             # the referent is constructed in this scope
82             # jump to this package
83 0           return ($1 . ".pm", $method);
84              
85             }
86              
87             # check if the referent is a package method
88             # my $car = CarFactory::get_car();
89 0 0         if ($current_scope =~ /my\s+\$$referent\s+=\s+(\w+)::(\w+)/) {
90             ### look up the referent in the current scope?
91             # e.g. my $car = CarFactory::getCar
92 0           return ($1 . ".pm", $2);
93             }
94              
95             }
96              
97             }
98              
99              
100             ###############################################################################
101             #
102             # process - given a string, look for there_docs and then do things if you
103             # find one!
104             #
105             ###############################################################################
106              
107             sub process {
108              
109 0     0 1   my ($this, $thing) = @_;
110              
111             # match the string the ThereDoc is targetting <<< this bit
112 0           my ($mode, $target_string, $theredoc_line_number) =
113             $this->find_there_doc($thing->get_full_path());
114              
115             # Prompter::notify("found there_doc with mode $mode at $target_string + $theredoc_line_number");
116              
117             # which package and method is the ThereDoc targetting?
118 0           my ($package, $method) =
119             $this->find_package_and_method($target_string, $thing->get_filename(),
120             $thing->get_full_path(), $theredoc_line_number);
121              
122              
123 0 0 0       if ($package && $method) {
124              
125             # Prompter::notify("ThereDoc targets: $package, $method");
126              
127 0           my $target_thing = Goo::Loader::load($package);
128 0           my $target_line_number =
129             Goo::Thing::pm::MethodMatcher::get_line_number($method, $target_thing->get_file());
130              
131             # jump back to where we were before we did the jump?
132 0           return ($theredoc_line_number, $target_thing, $mode, $target_line_number);
133              
134              
135             }
136              
137             # does the user want to jump to another Thing?
138 0           return $this->SUPER::process($thing->get_full_path());
139              
140              
141             }
142              
143             1;
144              
145              
146             __END__
147              
148             =head1 NAME
149              
150             Goo::Thing::pm::ThereDocManager - Process ThereDocs embedded Perl modules
151              
152             =head1 SYNOPSIS
153              
154             use Goo::Thing::pm::ThereDocManager;
155              
156             =head1 DESCRIPTION
157              
158             =head1 METHODS
159              
160             =over
161              
162             =item find_package_and_method
163              
164             return the method and package the ThereDoc is targetting
165              
166             =item process
167              
168             given a string, look for ThereDocs and then do actions
169              
170             =back
171              
172             =head1 AUTHOR
173              
174             Nigel Hamilton <nigel@trexy.com>
175              
176             =head1 SEE ALSO
177