database_builder_for_mysql.sql.txt SQL command to generate the tables in the database
tm_cgi.pl Very short program that need to be customized (see Instructions below)
TM.pm The core of the application. Store it in the same directory of tm_cgi.pl
topicmaps.gif Image
add.gif Image
remove.gif Image Save the images and the CSS file in a
xtm.css CSS file directory that can be read by the server.
Before running the CGI (tm_cgi.pl) remember to configure it. This is the CGI:
1 #! d:/Perl/bin/perl.exe 2 # By Luca Mugnaini 3 # http://www.geocities.com/lucamugnaini/tm/ 4 # use CGI::Carp qw(fatalsToBrowser); 5 use TM; 6 TM->connect('dbi:mysqlPP:database=topic_maps;host=localhost', '', ''); 7 $TM::image_directory = "/images"; 8 $TM::cgi_name = "tm_cgi.pl"; 9 print TM::cgi->cgi();
The only external module necessary to run this tool is DBI. Find it here: http://search.cpan.org/dist/DBI/
With this application you have an object oriented interface to store easily topic maps in a relational database. The most simple way to create a new topic is:
use TM; TM->connect('dbi:mysqlPP:database=topic_maps;host=localhost', '', ''); my $topic = TM::topic->new; $topic->save();To read the topic that has ID = 1:
my $topic = TM::topic->new(id => 1); $topic->load();To display the value of the first scope of the first occurrence of certain topic:
print $topic->{'occurrence'}->[0]->{'scope'}->[0]->{'content'};To change the value and save it:
$topic->{'occurrence'}->[0]->{'scope'}->[0]->{'content'} = 'new value'; $topic->save();To display all the attributes of a topic:
use Data::Dumper; print Dumper($topic);To create a topic that is instance of the topic #1 and topic #2:
my $topic = TM::topic->new ( instanceOf => [ TM::instanceOf->new( content => '#1', type => 't' ), TM::instanceOf->new( content => '#2', type => 't' ), ], ); $topic->save();To add a new instance for topic #3
push @{$topic->{instanceOf}}, TM::instanceOf->new( content => '#3', type => 't' ); $topic->save();To remove this last instance (both from the database and from the object):
$topic->{intanceOf}->[2]->remove($topic);To remove the whole topic:
$topic->remove($topic);To output the part of XML related to topics (sorry, I forget to build a method that generate all the XML. For the next version...):
TM::cgi::create_xml('topic');