1package 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 37use strict; 38 39use File::Grep qw(fdo); 40use File::NCopy qw(copy); 41 42use Goo::Object; 43use Goo::Loader; 44use Goo::Prompter; 45use Goo::TrailManager; 46use Goo::LiteDatabase; 47 48use base qw(Goo::Object); 49 50our $VERSION = '0.09'; 51 52 53############################################################################### 54# 55# check_environment - is everything set up OK? 56# 57############################################################################### 58 59sub check_environment { 60 61 my $db_directory = "$ENV{HOME}/.goo"; # store the DB in ~/.goo 62 my $db_file = "$db_directory/goo-trail.db"; # in the file goo-trail.db 63 64 if (-e $db_file) { # datbase file is present 65 Goo::LiteDatabase::get_connection($db_file); # connect to db 66 return; # and bail out 67 } 68 69 # no database yet - let's make one? 70 # check if the ~/.goo directory is present? 71 if (!-d $db_directory) { # if there is no directory 72 if (-e $db_directory) { # but a file with the name .goo 73 rename $db_directory, "$db_directory.wtf"; # move it 74 } 75 76 print "~/.goo directory was not present, so I will create one now\n"; 77 print "and populate it with common things. You can customize it later.\n"; 78 79 mkdir $db_directory; # make the ~/.goo directory 80 for(@INC) { # lookup all @INC directories 81 if(-e "$_/.gooskel") { # if we found the goo skeletton dir 82 copy(\1, "$_/.gooskel/*", $db_directory); 83 last; 84 } 85 } 86 } 87 88 close DATA if (open DATA, ">>$db_file"); # make the db file ("touch") 89 90 # connect to the database for the first time 91 Goo::LiteDatabase::get_connection($db_file); 92 93 # create all the tables 94 Goo::TrailManager::create_database(); 95 96} 97 98 99############################################################################### 100# 101# doAction - edit a template etc 102# 103############################################################################### 104 105sub do_action { 106 107 my ($this, $action, $filename, @parameters) = @_; 108 109 # special exception for makers - need to remove this later 110 if ($action =~ /M/i) { 111 112 $filename = "$ENV{HOME}/.goo/things/goo/$filename"; 113 114 if (-e $filename) { 115 return 116 unless Goo::Prompter::confirm( 117 "The file $filename already exists. Continue making?", 118 "N"); 119 } 120 121 my $maker = Goo::Loader::get_maker($filename); 122 $maker->run($filename); 123 124 } else { 125 126 # if the filename exists in the current directory 127 my $thing = Goo::Loader::load($filename); 128 129 # can the Thing do the action? 130 if ($thing->can_do_action($action)) { 131 132 # print "thing can do $action \n"; 133 # dynamically call the matching method 134 $thing->do_action($action, @parameters); 135 136 } else { 137 138 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 153sub BEGIN { 154 155 # check and set up the environment 156 check_environment(); 157 158} 159 160 1611; 162 163 164__END__ 165 166=head1 NAME 167 168Goo - Stick Things together with The Goo 169 170=head1 SYNOPSIS 171 172shell> goo -p Object.pm # show a [P]rofile of Object.pm 173 174shell> goo -l Object.pm # show Back [L]inks to Object.pm 175 176shell> goo -r Object.pm # [R]un Object.pm 177 178shell> goo -i Object.pm # comp[I]le Object.pm 179 180shell> goo -p access.log # show a [P]rofile of access.log 181 182shell> goo -c Object.pm # [C]lone Object.pm into another Thing 183 184shell> goo -o # the Care[O]Meter shows Things you care about while coding (e.g., tasks, bugs) 185 186shell> 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 192Things include Perl modules, Perl scripts, log files, javascripts, configuration files, database tables, templates etc. 193 194The Goo records a "Trail" as you jump quickly from Thing to Thing in a simple, text-based console. It remembers how you 195associate Things in your environment. 196 197Accelerate your work by quickly traversing the Trail of associations between Things. 198 199=head1 METHODS 200 201=over 202 203=item check_environment 204 205Check and set up the environment. 206 207=item do_action 208 209Take a command line switch (e.g., -p) and map it to an action handler (e.g., [P]rofile) and perform the action on the 210Thing. 211 212=back 213 214=head1 AUTHOR 215 216Nigel Hamilton <nigel@trexy.com> 217 218=head1 SEE ALSO 219 220Tour http://thegoo.org/goo-tour.pdf (big) 221 222Web http://thegoo.org 223 224Blog http://blog.thegoo.org 225