From: <pau...@us...> - 2008-06-22 08:20:18
|
Revision: 1003 http://everydevel.svn.sourceforge.net/everydevel/?rev=1003&view=rev Author: paul_the_nomad Date: 2008-06-22 01:20:13 -0700 (Sun, 22 Jun 2008) Log Message: ----------- Changes to Everything::Config to allow relative config file names in httpd.conf and to allow relative database names when the database is sqlite. Changes to the files used by t/TEST to take advantage of relative file names. Fixes in CGI.pm to allow for the config system. Also changes to SimpleServer.pm so that that now works with Config.pm. Modified Paths: -------------- trunk/ebase/bin/simple-server.pl trunk/ebase/lib/Everything/CmdLine.pm trunk/ebase/lib/Everything/Config.pm trunk/ebase/lib/Everything/HTML.pm trunk/ebase/lib/Everything/HTTP/CGI.pm trunk/ebase/lib/Everything/HTTP/Response/Htmlpage.pm trunk/ebase/lib/Everything/Storage/Test/Nodeball.pm trunk/ebase/lib/Everything/Test/Config.pm trunk/ebase/lib/Everything/Test/Ecore/SimpleServer.pm trunk/ebase/lib/Everything/Test/HTML.pm trunk/ebase/scripts/everything-startup.pl trunk/ebase/t/conf/extra.conf.in trunk/ebase/t/lib/everything.conf Modified: trunk/ebase/bin/simple-server.pl =================================================================== --- trunk/ebase/bin/simple-server.pl 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/bin/simple-server.pl 2008-06-22 08:20:13 UTC (rev 1003) @@ -3,15 +3,23 @@ use strict; use warnings; use Carp qw/croak confess cluck/; -use Everything::CmdLine qw/abs_path get_options make_nodebase/; +use Everything::CmdLine qw/abs_path get_options make_nodebase config/; use Everything::Test::Ecore::SimpleServer; -$SIG{__DIE__} =\&confess; +$SIG{__DIE__} = \&confess; + #$SIG{__WARN__} =\&cluck; $|++; -my $opts = get_options( undef, [ 'listenport=i'] ); +my $opts = get_options( undef, ['listenport=i'] ); $$opts{type} ||= 'sqlite'; -my $server = Everything::Test::Ecore::SimpleServer->new( { mod_perlInit => ["$$opts{database}:$$opts{user}:$$opts{password}:$$opts{host}", { dbtype => $$opts{type}} ], listenport => $$opts{'listenport'} } ); + +my $config = config($opts); + +my $server = Everything::Test::Ecore::SimpleServer->new( { + config => $config, + listenport => $$opts{'listenport'} +} +); $server->run; Modified: trunk/ebase/lib/Everything/CmdLine.pm =================================================================== --- trunk/ebase/lib/Everything/CmdLine.pm 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/lib/Everything/CmdLine.pm 2008-06-22 08:20:13 UTC (rev 1003) @@ -1,5 +1,6 @@ package Everything::CmdLine; +use Everything::Config; use Getopt::Long; use Term::ReadKey; use Cwd; @@ -8,7 +9,7 @@ use strict; use warnings; -our @EXPORT_OK = qw(get_options abs_path usage_options make_nodebase readline_quick confirm_yn); +our @EXPORT_OK = qw(get_options abs_path usage_options make_nodebase readline_quick confirm_yn config); Getopt::Long::Configure(qw/bundling/); @@ -104,6 +105,18 @@ return $nb; } +sub config { + my ( $arg ) = @_; + my $opts = $arg || get_options; + my $c = Everything::Config->new; + $c->database_name( $$opts{ database } ); + $c->database_user( $$opts{ user } ); + $c->database_password( $$opts{ password } ); + $c->database_host( $$opts{ host } ); + $c->database_port( $$opts{ port } ); + $c->database_type( $$opts{ type } ); + return $c; +} sub readline_quick { Modified: trunk/ebase/lib/Everything/Config.pm =================================================================== --- trunk/ebase/lib/Everything/Config.pm 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/lib/Everything/Config.pm 2008-06-22 08:20:13 UTC (rev 1003) @@ -1,6 +1,8 @@ package Everything::Config; use AppConfig qw/ :argcount /; +use File::Spec; +use File::Basename; use Everything '$DB'; use Everything::NodeBase; use Cwd qw/abs_path/; @@ -28,7 +30,7 @@ my $config = AppConfig->new; foreach ( - qw/database_name database_user database_password database_host database_type/ + qw/database_name database_user database_password database_host database_port database_type/ ) { $config->define( $_, { DEFAULT => '', ARGCOUNT => ARGCOUNT_ONE } ); @@ -58,15 +60,19 @@ my $r = $self->get_apache_request; if ( ! $file && $r ) { - $file = $r->dir_config->get('everything-config-file'); + my $f = $r->dir_config->get('everything-config-file'); + my $base = Apache2::ServerUtil::server_root(); + $file = File::Spec->rel2abs( $f, $base ); + } ## first the file - $config->file( abs_path( $file ) ) if $file; + $config->file( $file ) if $file; + make_db_path_absolute( $config, ( fileparse( $file ) )[1] ) if $file; + ## now apache request - read_apache_request( $config, $self->get_apache_request ) - if $self->get_apache_request; + read_apache_request( $config, $r ) if $r; $self->set( \@config, $config ); @@ -74,13 +80,23 @@ } } + +sub make_db_path_absolute { + + my ( $config, $base ) = @_; + return unless $config->get('database_type') eq 'sqlite'; + my $db_name = File::Spec->rel2abs( $config->get('database_name'), $base ); + $config->set('database_name', $db_name ); + +} + sub read_apache_request { my ( $config, $r ) = @_; my $apr_table = $r->dir_config; foreach ( - qw/database_name database_user database_password database_host database_type/ + qw/database_name database_user database_password database_host database_port database_type/ ) { my $attribute = $_; $attribute =~ s/_/\-/; @@ -88,17 +104,9 @@ my $value = $apr_table->get( $attribute ); $config->set( $_, $value ) if $value; } -# $config->set( 'database_name', -# $apr_table->get('everything-database-name') || '' ); -# $config->set( 'database_user', -# $apr_table->get('everything-database-user') || '' ); -# $config->set( 'database_password', -# $apr_table->get('everything-database-password') || '' ); -# $config->set( 'database_host', -# $apr_table->get('everything-database-host') || '' ); -# $config->set( 'database_type', -# $apr_table->get('everything-database-type') || '' ); + make_db_path_absolute( $config, Apache2::ServerUtil::server_root() ); + } @@ -261,7 +269,9 @@ =item database_name -The name of the database +The name of the database. In the case of sqlite, this is a file +name. A relative path may be specified, in which case it is relative +to the location of the config file. =item database_user @@ -275,6 +285,10 @@ The host +=item database_port + +The port to which to connect to the database. + =item database_type The type of the database we will connect to must be 'mysql', 'sqlite' or 'Pg' without the quotes. @@ -316,6 +330,14 @@ Where C< /schema/type > is the schema and C<nodetypename> is the nodetype. +=item location_code + +There may be more than one of these. This is perl code that must be +able to eval'd as an anonymous subroutine. It will be passed one +argument, a node object, and should return the local url location of +that node, say, for example, C</node/nodeid>. + + =back @@ -333,11 +355,12 @@ =item everything-config-file -Name of the config file +Name of the config file. If a relative path, it must be relative to +value set by Apache's ServerRoot directive. =item everything-database-name -Database name to connect to +Database name to connect to. If the database type is 'sqlite', this is a file name which may be relative to the Apache directive C<ServerRoot>. =item everything-database-user @@ -347,6 +370,14 @@ The database password for the above mentioned user +=item everything-database-host + +The host + +=item everything-database-port + +The port + =item everything-database-type The type of database "mysql", "Pg" or "sqlite". Modified: trunk/ebase/lib/Everything/HTML.pm =================================================================== --- trunk/ebase/lib/Everything/HTML.pm 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/lib/Everything/HTML.pm 2008-06-22 08:20:13 UTC (rev 1003) @@ -646,7 +646,11 @@ my $scripts = handle_scripts($SCRIPTS); my $node_location = $self->node_location( $NODE ); - $$PARAMS{node_id} = $NODE->{node_id} unless $node_location; + + if ( ! $node_location ) { + $$PARAMS{node_id} = $NODE->{node_id}; + $node_location = '/'; + } $link = "<a href=" . $self->url_gen($PARAMS, undef, $node_location) . $tags; $link .= " " . $scripts if ( $scripts ne "" ); Modified: trunk/ebase/lib/Everything/HTTP/CGI.pm =================================================================== --- trunk/ebase/lib/Everything/HTTP/CGI.pm 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/lib/Everything/HTTP/CGI.pm 2008-06-22 08:20:13 UTC (rev 1003) @@ -41,7 +41,7 @@ my $response = Everything::HTTP::ResponseFactory->new( 'htmlpage', $e ); $response->create_http_body; my $html = $response->get_http_body; - my $header = $e->http_header( $response->get_mime_type ); + my $header = $e->http_header( $response->content_type ); $e->get_cgi->print($header); $e->get_cgi->print($html); Modified: trunk/ebase/lib/Everything/HTTP/Response/Htmlpage.pm =================================================================== --- trunk/ebase/lib/Everything/HTTP/Response/Htmlpage.pm 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/lib/Everything/HTTP/Response/Htmlpage.pm 2008-06-22 08:20:13 UTC (rev 1003) @@ -33,7 +33,10 @@ my $config = $$args{ config }; my $ehtml = Everything::HTML->new; - $ehtml->set_node_locators( $config->node_locations ); + if ( $config ) { + $ehtml->set_node_locators( $config->node_locations ); + } + $self->getTheme( $self->get_request ); $ehtml->set_request( $self->get_request ); Modified: trunk/ebase/lib/Everything/Storage/Test/Nodeball.pm =================================================================== --- trunk/ebase/lib/Everything/Storage/Test/Nodeball.pm 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/lib/Everything/Storage/Test/Nodeball.pm 2008-06-22 08:20:13 UTC (rev 1003) @@ -8,7 +8,7 @@ use File::Temp; use File::Path; use File::Find; -use Archive::Tar; +#use Archive::Tar; use IO::File; use SQL::Statement; use Cwd; @@ -16,10 +16,12 @@ use warnings; sub startup : Test(+1) { + + ### use-ing Archive::Tar causes a seg fault. Bug in perl 5.10?? + require 'Archive/Tar.pm'; my $self = shift; $self->SUPER::startup; my $instance = $self->{class}->new; - my ( $test_nodeball_d, $test_nodeball ) = $self->make_test_nodeball; $self->{test_nodeball_d} = $test_nodeball_d; $self->{test_nodeball} = $test_nodeball; Modified: trunk/ebase/lib/Everything/Test/Config.pm =================================================================== --- trunk/ebase/lib/Everything/Test/Config.pm 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/lib/Everything/Test/Config.pm 2008-06-22 08:20:13 UTC (rev 1003) @@ -4,8 +4,9 @@ use SUPER; use Test::More; use Test::MockObject; +use File::Basename; +use File::Spec; use File::Temp qw/:seekable/; -#use Everything::Config; use strict; use warnings; @@ -205,4 +206,41 @@ is ( $inst->database_type, '', '...database type defaults to empty string.'); } +sub test_sqlite_file_paths : Test(2) { + + my $self = shift; + my $fh = File::Temp->new(); + print $fh <<HERE; +database_name = sqlite_db +database_type = sqlite +HERE + + $fh->seek( 0, SEEK_SET ); + my $inst = $self->{class}->new( file => "$fh" ); + my $path = ( fileparse("$fh") )[1]; + is( + $inst->get_config->get('database_name'), + File::Spec->catfile( $path, 'sqlite_db' ), + '...makes sqlite file name absolute.' + ); + + my $mock = Test::MockObject->new; + $mock->set_always( dir_config => $mock ); + $mock->set_series( get => 'apache_sqlite_db', '', '', '', 'sqlite' ); + + local *Apache2::ServerUtil::server_root; + *Apache2::ServerUtil::server_root = + sub { File::Spec->catfile( File::Spec->rootdir, qw/blah blah blah/ ) }; + + $fh->seek( 0, SEEK_SET ); + $inst = $self->{class}->new( file => "$fh", apache_request => $mock ); + is( + $inst->get_config->get('database_name'), + File::Spec->catfile( + File::Spec->rootdir, qw/blah blah blah apache_sqlite_db/ + ), + '...makes sqlite file name, set in httpd.conf absolute.' + ); +} + 1; Modified: trunk/ebase/lib/Everything/Test/Ecore/SimpleServer.pm =================================================================== --- trunk/ebase/lib/Everything/Test/Ecore/SimpleServer.pm 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/lib/Everything/Test/Ecore/SimpleServer.pm 2008-06-22 08:20:13 UTC (rev 1003) @@ -12,6 +12,7 @@ my $port = $$args{listenport}; my $self = $class->SUPER($port); $self->{mod_perlInit} = $$args{mod_perlInit}; + $self->{config} = $$args{config}; ## to deal with unwanted behaviour $Everything::commandLine = 0; @@ -28,9 +29,9 @@ local *Everything::HTML::getCGI; *Everything::HTML::getCGI = sub { $cgi }; - my $args = $self->{mod_perlInit}; + my $args = $self->{config}; - Everything::HTTP::CGI->handle( @$args ); + Everything::HTTP::CGI->handle( $args ); } Modified: trunk/ebase/lib/Everything/Test/HTML.pm =================================================================== --- trunk/ebase/lib/Everything/Test/HTML.pm 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/lib/Everything/Test/HTML.pm 2008-06-22 08:20:13 UTC (rev 1003) @@ -144,15 +144,15 @@ $mock->{title} = "Random node"; $m->set_always( getNode => $mock ); - is( $inst->link_node(1), '<a href="?node_id=111">Random node</a>', "linkNode" ); + is( $inst->link_node(1), '<a href="/?node_id=111">Random node</a>', "linkNode" ); $mock->{node_id} = 222; $mock->{title} = "Another Random Node"; - is( $inst->link_node($mock), '<a href="?node_id=222">Another Random Node</a>', + is( $inst->link_node($mock), '<a href="/?node_id=222">Another Random Node</a>', "linkNode" ); is( $inst->link_node( $mock, "Different Title" ), - '<a href="?node_id=222">Different Title</a>', "linkNode" ); + '<a href="/?node_id=222">Different Title</a>', "linkNode" ); is( $inst->link_node( $mock, "Different Title", { op => 'hello' } ), - '<a href="?node_id=222;op=hello">Different Title</a>', "linkNode" ); + '<a href="/?node_id=222;op=hello">Different Title</a>', "linkNode" ); is( $inst->link_node( @@ -161,7 +161,7 @@ { op => 'hello' }, { style => "Foo: bar" } ), - '<a href="?node_id=222;op=hello" style="Foo: bar">Different Title</a>', + '<a href="/?node_id=222;op=hello" style="Foo: bar">Different Title</a>', "linkNode" ); @@ -179,7 +179,7 @@ $mock->{title} = "Random node"; $m->set_always( getNode => $mock ); - is( $inst->link_node(1), '<a href="?node_id=111">Random node</a>', "...if no location returns node_id as param." ); + is( $inst->link_node(1), '<a href="/?node_id=111">Random node</a>', "...if no location returns node_id as param." ); $inst->set_node_locators ( [ sub{ '/a/location' } ] ); is( $inst->link_node(1), '<a href="/a/location">Random node</a>', "...if location returns location" ); Modified: trunk/ebase/scripts/everything-startup.pl =================================================================== --- trunk/ebase/scripts/everything-startup.pl 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/scripts/everything-startup.pl 2008-06-22 08:20:13 UTC (rev 1003) @@ -7,9 +7,9 @@ use Everything::Node::setting (); use Everything::HTTP::Request (); use Everything::HTTP::Apache (); -use Everything::HTTP::URL (); -use Everything::HTTP::URL::Deconstruct (); +use Everything::Config (); use Everything::CacheQueue (); +use Apache::DBI; use Everything::NodeCache (); use Carp; Modified: trunk/ebase/t/conf/extra.conf.in =================================================================== --- trunk/ebase/t/conf/extra.conf.in 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/t/conf/extra.conf.in 2008-06-22 08:20:13 UTC (rev 1003) @@ -3,10 +3,5 @@ </Perl> SetHandler perl-script -PerlSetVar everything-config-file @SERVERROOT@/lib/everything.conf -PerlSetVar everything-database-name @SERVERROOT@/ecore.db -PerlSetVar everything-database-type sqlite +PerlSetVar everything-config-file lib/everything.conf PerlResponseHandler +Everything::HTTP::Apache - -#PerlSetVar everything-url /node/:node_id -#PerlAddVar everything-url node Modified: trunk/ebase/t/lib/everything.conf =================================================================== --- trunk/ebase/t/lib/everything.conf 2008-06-15 13:20:32 UTC (rev 1002) +++ trunk/ebase/t/lib/everything.conf 2008-06-22 08:20:13 UTC (rev 1003) @@ -1,5 +1,6 @@ +database_name = ../ecore.db +database_type = sqlite - location_schema_nodetype = /node/:node_id node request_modifier_code = <<"FOOFOO" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |