| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Goo; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | ############################################################################### | 
| 4 |  |  |  |  |  |  | # Nigel Hamilton | 
| 5 |  |  |  |  |  |  | # | 
| 6 |  |  |  |  |  |  | # Copyright Nigel Hamilton 2005 | 
| 7 |  |  |  |  |  |  | # All Rights Reserved | 
| 8 |  |  |  |  |  |  | # | 
| 9 |  |  |  |  |  |  | # Author:       Nigel Hamilton | 
| 10 |  |  |  |  |  |  | # Filename:     Goo.pm | 
| 11 |  |  |  |  |  |  | # Description:  Stick Things together with The Goo | 
| 12 |  |  |  |  |  |  | # | 
| 13 |  |  |  |  |  |  | #               See: http://thegoo.org | 
| 14 |  |  |  |  |  |  | #                    http://blog.thegoo.org | 
| 15 |  |  |  |  |  |  | # | 
| 16 |  |  |  |  |  |  | # Date          Change | 
| 17 |  |  |  |  |  |  | # ----------------------------------------------------------------------------- | 
| 18 |  |  |  |  |  |  | # 27/03/2004    Auto generated file | 
| 19 |  |  |  |  |  |  | # 27/03/2004    Reduce work, bugs, documentation, and maintenance | 
| 20 |  |  |  |  |  |  | # 29/10/2004    Used filename suffixes to determine what to do - added a lot of | 
| 21 |  |  |  |  |  |  | #               the Goo's basic functionality in one go! | 
| 22 |  |  |  |  |  |  | # 02/02/2005    Returned to add more functions | 
| 23 |  |  |  |  |  |  | # 07/02/2005    Moved dynamic "use" to "require" to stop connecting to the Master | 
| 24 |  |  |  |  |  |  | #               DB on startup for faster running | 
| 25 |  |  |  |  |  |  | # 10/02/2005    Added a program editor for fast edits and test updates. | 
| 26 |  |  |  |  |  |  | #               Added a ProgramCloner and ProgramEditor | 
| 27 |  |  |  |  |  |  | # 16/06/2005    Added meta-goo descriptions in /home/search/goo - dramatically | 
| 28 |  |  |  |  |  |  | #               simplified the code for this program. | 
| 29 |  |  |  |  |  |  | # 01/08/2005    Meta details stored in Config files help to simplify this part | 
| 30 |  |  |  |  |  |  | #               of the code even more - this unifies the command-line and [E]dit | 
| 31 |  |  |  |  |  |  | #               processing steps. | 
| 32 |  |  |  |  |  |  | # 17/10/2005    Added method: loadMaker | 
| 33 |  |  |  |  |  |  | # 23/11/2005    Added check_environment() to help with CPAN-friendly install | 
| 34 |  |  |  |  |  |  | # | 
| 35 |  |  |  |  |  |  | ############################################################################### | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 1 |  |  | 1 |  | 33278 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 41 |  | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 1 |  |  | 1 |  | 820 | use File::Grep  qw(fdo); | 
|  | 1 |  |  |  |  | 1441 |  | 
|  | 1 |  |  |  |  | 68 |  | 
| 40 | 1 |  |  | 1 |  | 1002 | use File::NCopy qw(copy); | 
|  | 1 |  |  |  |  | 3321 |  | 
|  | 1 |  |  |  |  | 66 |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 1 |  |  | 1 |  | 528 | use Goo::Object; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 43 | 1 |  |  | 1 |  | 500 | use Goo::Loader; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 44 | 1 |  |  | 1 |  | 7 | use Goo::Prompter; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 19 |  | 
| 45 | 1 |  |  | 1 |  | 5 | use Goo::TrailManager; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 46 | 1 |  |  | 1 |  | 6 | use Goo::LiteDatabase; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 24 |  | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 1 |  |  | 1 |  | 6 | use base qw(Goo::Object); | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 783 |  | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | our $VERSION = '0.09'; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | ############################################################################### | 
| 54 |  |  |  |  |  |  | # | 
| 55 |  |  |  |  |  |  | # check_environment - is everything set up OK? | 
| 56 |  |  |  |  |  |  | # | 
| 57 |  |  |  |  |  |  | ############################################################################### | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | sub check_environment { | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 1 |  |  | 1 |  | 6 | my $db_directory = "$ENV{HOME}/.goo";              # store the DB in ~/.goo | 
| 62 | 1 |  |  |  |  | 5 | my $db_file      = "$db_directory/goo-trail.db";   # in the file goo-trail.db | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 1 | 50 |  |  |  | 26 | if (-e $db_file) {                                 # datbase file is present | 
| 65 | 0 |  |  |  |  | 0 | Goo::LiteDatabase::get_connection($db_file);   # connect to db | 
| 66 | 0 |  |  |  |  | 0 | return;                                        # and bail out | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | # no database yet - let's make one? | 
| 70 |  |  |  |  |  |  | # check if the ~/.goo directory is present? | 
| 71 | 1 | 50 |  |  |  | 18 | if (!-d $db_directory) {    		       # if there is no directory | 
| 72 | 1 | 50 |  |  |  | 20 | if (-e $db_directory) {   	               # but a file with the name .goo | 
| 73 | 0 |  |  |  |  | 0 | rename $db_directory, "$db_directory.wtf"; # move it | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 1 |  |  |  |  | 32 | print "~/.goo directory was not present, so I will create one now\n"; | 
| 77 | 1 |  |  |  |  | 7 | print "and populate it with common things. You can customize it later.\n"; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 1 |  |  |  |  | 78 | mkdir $db_directory;                 # make the ~/.goo directory | 
| 80 | 0 |  |  |  |  |  | for(@INC) {                          # lookup all @INC directories | 
| 81 | 0 | 0 |  |  |  |  | if(-e "$_/.gooskel") {           # if we found the goo skeletton dir | 
| 82 | 0 |  |  |  |  |  | copy(\1, "$_/.gooskel/*", $db_directory); | 
| 83 | 0 |  |  |  |  |  | last; | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 0 | 0 |  |  |  |  | close DATA if (open DATA, ">>$db_file"); # make the db file ("touch") | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | # connect to the database for the first time | 
| 91 | 0 |  |  |  |  |  | Goo::LiteDatabase::get_connection($db_file); | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | # create all the tables | 
| 94 | 0 |  |  |  |  |  | Goo::TrailManager::create_database(); | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | ############################################################################### | 
| 100 |  |  |  |  |  |  | # | 
| 101 |  |  |  |  |  |  | # doAction - edit a template etc | 
| 102 |  |  |  |  |  |  | # | 
| 103 |  |  |  |  |  |  | ############################################################################### | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | sub do_action { | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 0 |  |  | 0 |  |  | my ($this, $action, $filename, @parameters) = @_; | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | # special exception for makers - need to remove this later | 
| 110 | 0 | 0 |  |  |  |  | if ($action =~ /M/i) { | 
| 111 |  |  |  |  |  |  |  | 
| 112 | 0 |  |  |  |  |  | $filename = "$ENV{HOME}/.goo/things/goo/$filename"; | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 0 | 0 |  |  |  |  | if (-e $filename) { | 
| 115 |  |  |  |  |  |  | return | 
| 116 | 0 | 0 |  |  |  |  | unless Goo::Prompter::confirm( | 
| 117 |  |  |  |  |  |  | "The file $filename already exists. Continue making?", | 
| 118 |  |  |  |  |  |  | "N"); | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 0 |  |  |  |  |  | my $maker = Goo::Loader::get_maker($filename); | 
| 122 | 0 |  |  |  |  |  | $maker->run($filename); | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | } else { | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | # if the filename exists in the current directory | 
| 127 | 0 |  |  |  |  |  | my $thing = Goo::Loader::load($filename); | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | # can the Thing do the action? | 
| 130 | 0 | 0 |  |  |  |  | if ($thing->can_do_action($action)) { | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | # print "thing can do $action \n"; | 
| 133 |  |  |  |  |  |  | # dynamically call the matching method | 
| 134 | 0 |  |  |  |  |  | $thing->do_action($action, @parameters); | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | } else { | 
| 137 |  |  |  |  |  |  |  | 
| 138 | 0 |  |  |  |  |  | Goo::Prompter::stop("Goo invalid action $action for this Thing: $filename."); | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | } | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | } | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | } | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | ############################################################################### | 
| 148 |  |  |  |  |  |  | # | 
| 149 |  |  |  |  |  |  | # BEGIN - is everything set up OK? | 
| 150 |  |  |  |  |  |  | # | 
| 151 |  |  |  |  |  |  | ############################################################################### | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | sub BEGIN { | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | # check and set up the environment | 
| 156 | 1 |  |  | 1 |  | 4 | check_environment(); | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | } | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | 1; | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | __END__ | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | =head1 NAME | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | Goo - Stick Things together with The Goo | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | shell> goo -p Object.pm		# show a [P]rofile of Object.pm | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | shell> goo -l Object.pm		# show Back [L]inks to Object.pm | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | shell> goo -r Object.pm		# [R]un Object.pm | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | shell> goo -i Object.pm		# comp[I]le Object.pm | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | shell> goo -p access.log		# show a [P]rofile of access.log | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | shell> goo -c Object.pm		# [C]lone Object.pm into another Thing | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | shell> goo -o				# the Care[O]Meter shows Things you care about while coding (e.g., tasks, bugs) | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | shell> goo -z				# show Things in your working [Z]one or mental buffer | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | "The Goo" helps you stick "Things" together in your working environment. | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | Things include Perl modules, Perl scripts, log files, javascripts, configuration files, database tables, templates etc. | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | The Goo records a "Trail" as you jump quickly from Thing to Thing in a simple, text-based console. It remembers how you | 
| 195 |  |  |  |  |  |  | associate Things in your environment. | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | Accelerate your work by quickly traversing the Trail of associations between Things. | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | =head1 METHODS | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | =over | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | =item check_environment | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | Check and set up the environment. | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | =item do_action | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | Take a command line switch (e.g., -p) and map it to an action handler (e.g., [P]rofile) and perform the action on the | 
| 210 |  |  |  |  |  |  | Thing. | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | =back | 
| 213 |  |  |  |  |  |  |  | 
| 214 |  |  |  |  |  |  | =head1 AUTHOR | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | Nigel Hamilton <nigel@trexy.com> | 
| 217 |  |  |  |  |  |  |  | 
| 218 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | Tour	http://thegoo.org/goo-tour.pdf (big) | 
| 221 |  |  |  |  |  |  |  | 
| 222 |  |  |  |  |  |  | Web 	http://thegoo.org | 
| 223 |  |  |  |  |  |  |  | 
| 224 |  |  |  |  |  |  | Blog	http://blog.thegoo.org |