From: <chr...@us...> - 2006-06-14 22:21:22
|
Revision: 890 Author: chromatic Date: 2006-06-14 15:21:11 -0700 (Wed, 14 Jun 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=890&view=rev Log Message: ----------- r17845@windwheel: chromatic | 2006-06-14 15:20:57 -0700 Split buildNodetypeModules() between Everything::DB and Everything::NodeBase. Revised tests for new version. Modified Paths: -------------- trunk/ebase/lib/Everything/DB.pm trunk/ebase/lib/Everything/NodeBase.pm trunk/ebase/lib/Everything/Test/NodeBase.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17843 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17845 Modified: trunk/ebase/lib/Everything/DB.pm =================================================================== --- trunk/ebase/lib/Everything/DB.pm 2006-06-14 21:17:13 UTC (rev 889) +++ trunk/ebase/lib/Everything/DB.pm 2006-06-14 22:21:11 UTC (rev 890) @@ -20,33 +20,28 @@ bless \%args, $class; } -=head2 C<buildNodetypeModules> +=head2 C<fetch_all_nodetype_names()> -Perl 5.6 throws errors if we test "can" on a non-existing module. This -function builds a hashref with keys to all of the modules that exist in the -Everything::Node:: dir This also casts "use" on the modules, loading them into -memory +This method returns a list of the names of all nodetypes in the system. =cut -sub buildNodetypeModules +sub fetch_all_nodetype_names { - my ($this) = @_; + my $self = shift; + my $csr = $self->sqlSelectMany( 'title', 'node', 'type_nodetype=1' ); - my $csr = $this->sqlSelectMany( 'title', 'node', 'type_nodetype=1' ); return unless $csr; - my %modules; + my @modules; while ( my ($title) = $csr->fetchrow_array() ) { $title =~ s/\W//g; - my $modname = "Everything::Node::$title"; - - $modules{$modname} = 1 if $this->loadNodetypeModule($modname); + push @modules, $title; } - return \%modules; + return @modules; } =head2 C<getDatabaseHandle> Modified: trunk/ebase/lib/Everything/NodeBase.pm =================================================================== --- trunk/ebase/lib/Everything/NodeBase.pm 2006-06-14 21:17:13 UTC (rev 889) +++ trunk/ebase/lib/Everything/NodeBase.pm 2006-06-14 22:21:11 UTC (rev 890) @@ -23,7 +23,7 @@ BEGIN { my @methlist = qw( - buildNodetypeModules getDatabaseHandle sqlDelete sqlSelect sqlSelectJoined + getDatabaseHandle sqlDelete sqlSelect sqlSelectJoined sqlSelectMany sqlSelectHashref sqlUpdate sqlInsert _quoteData sqlExecute getNodeByIdNew getNodeByName constructNode selectNodeWhere getNodeCursor countNodeMatches getAllTypes dropNodeTable quote genWhereString @@ -87,7 +87,7 @@ $this->{storage} = $storage_class->new( cache => $this->{cache} ); $this->{storage}->databaseConnect( $dbname, $host, $user, $pass ); - $this->{nodetypeModules} = $this->{storage}->buildNodetypeModules(); + $this->{nodetypeModules} = $this->buildNodetypeModules(); if ( $this->getType('setting') ) { @@ -137,6 +137,30 @@ $this->joinWorkspace( $WORKSPACE ); } +=head2 C<buildNodetypeModules> + +Perl 5.6 throws errors if we test "can" on a non-existing module. This +function builds a hashref with keys to all of the modules that exist in the +Everything::Node:: dir This also casts "use" on the modules, loading them into +memory + +=cut + +sub buildNodetypeModules +{ + my $self = shift; + + my %modules; + + for my $nodetype ( $self->{storage}->fetch_all_nodetype_names() ) + { + my $module = "Everything::Node::$nodetype"; + $modules{ $module } = 1 if $self->loadNodetypeModule( $module ); + } + + return \%modules; +} + =head2 C<rebuildNodetypeModules> Call this to account for any new nodetypes that may have been installed. Modified: trunk/ebase/lib/Everything/Test/NodeBase.pm =================================================================== --- trunk/ebase/lib/Everything/Test/NodeBase.pm 2006-06-14 21:17:13 UTC (rev 889) +++ trunk/ebase/lib/Everything/Test/NodeBase.pm 2006-06-14 22:21:11 UTC (rev 890) @@ -49,7 +49,8 @@ my $module = $self->module_class(); my $mock_db = Test::MockObject->new(); - $mock_db->set_false(qw( getNodeByIdNew getNodeByName )) + $mock_db->set_false(qw( getNodeByIdNew getNodeByName + -fetch_all_nodetype_names )) ->set_true(qw( databaseConnect buildNodetypeModules )) ->fake_module( 'Everything::DB::fake_db', 'new', sub { $mock_db }); @@ -60,7 +61,7 @@ BEGIN { for my $method (qw( - buildNodetypeModules getDatabaseHandle sqlDelete sqlSelect + getDatabaseHandle sqlDelete sqlSelect sqlSelectJoined sqlSelectMany sqlSelectHashref sqlUpdate sqlInsert _quoteData sqlExecute getNodeByIdNew getNodeByName constructNode selectNodeWhere getNodeCursor countNodeMatches getAllTypes @@ -121,6 +122,26 @@ '... reblessing into workspace package' ); } +sub test_build_nodetype_modules :Test( 2 ) +{ + my $self = shift; + my $nb = $self->{nb}; + my $storage = $self->{storage}; + + $nb->set_series( loadNodetypeModule => 1, 1, 0, 1 ); + $storage->mock( + fetch_all_nodetype_names => sub { qw( node nodetype cow dbtable ) } + ); + + my $result = $nb->buildNodetypeModules(); + is( keys %$result, 3, 'buildNodetypeModules() should return a hash ref' ); + is_deeply( + $result, + { map { 'Everything::Node::' . $_ => 1 } qw( node nodetype dbtable ) }, + '... for all loadable nodes fetched from storage engine' + ); +} + sub test_rebuild_nodetype_modules :Test( 1 ) { my $self = shift; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |