--- lib/Strix.pm 2008/06/16 13:16:57 171 +++ lib/Strix.pm 2008/06/16 21:29:50 182 @@ -4,11 +4,12 @@ use warnings; use base qw(Jifty::Object Class::Accessor::Fast); -__PACKAGE__->mk_accessors( qw(site uid) ); +__PACKAGE__->mk_accessors( qw(instance uid) ); use DBI; use Data::Dump qw/dump/; use Carp qw/confess/; +use Jifty; our $debug = 0; @@ -20,24 +21,24 @@ =head2 new - my $strix = Strix->new({ site => 'os-test0604-zg' }); + my $strix = Strix->new({ instance => 'os-test0604-zg' }); =head2 dbh - my $dbh = Strix->dbh( $site_name ); + my $dbh = Strix->dbh( $strix_instance ); my $dbh = $strix->dbh; =cut -our $site_dbh; +our $instance_dbh; sub dbh { my $self = shift; - my $site = shift || $self->site || confess "no site"; + my $instance = shift || ref($self) && $self->instance || confess "no instance"; - return $site_dbh->{$site} if $site_dbh->{$site}; + return $instance_dbh->{$instance} if $instance_dbh->{$instance}; my $config = Jifty->config->app('strix') or die "need strix config"; my $database = $config->{database} or die "no strix.database in config"; @@ -45,17 +46,17 @@ Jifty->log->debug("using config ", dump( $database )); my $dsn = - 'DBI:Pg:dbname=' . $site . + 'DBI:Pg:dbname=' . $instance . ';host=' . $database->{host} . ';port=' . $database->{port}; - Jifty->log->info("Connect to site $site with dsn $dsn"); + Jifty->log->info("Connect to instance $instance with dsn $dsn"); my $dbh = DBI->connect( $dsn, $database->{user}, $database->{passwd} ) or die $DBI::errstr; - $site_dbh->{$site} = $dbh; + $instance_dbh->{$instance} = $dbh; - warn "## site_dbh = ",dump( $site_dbh ); + warn "## instance_dbh = ",dump( $instance_dbh ) if $debug; return $dbh; } @@ -116,9 +117,19 @@ }); $sth->execute( $category->{template_id} ); + sub module_args { + my $row = shift; + return undef unless $row->{module_args}; + my $args; + foreach my $a ( split(/\&/, $row->{module_args} ) ) { + $args->{$1} = $2 if $a =~ m/^(.+)=(.+)$/; + } + return $args; + } + while (my $row = $sth->fetchrow_hashref() ) { warn dump( $row ) if $debug; - push @{ $page->{free} }, { $row->{name} => $row->{module_args} }; + push @{ $page->{free} }, { $row->{name} => module_args( $row ) }; } warn "### pre layout...\n" if $debug; @@ -138,7 +149,7 @@ while (my $row = $sth->fetchrow_hashref() ) { warn dump( $row ) if $debug; - push @{ $page->{pre}->{ $row->{pos} } }, { $row->{name} => $row->{module_args} }; + push @{ $page->{pre}->{ $row->{pos} } }, { $row->{name} => module_args( $row ) }; } warn "### post layout...\n" if $debug; @@ -153,7 +164,7 @@ while (my $row = $sth->fetchrow_hashref() ) { warn dump( $row ) if $debug; - push @{ $page->{post}->{ $row->{pozicija} } }, { $row->{name} => $row->{module_args} }; + push @{ $page->{post}->{ $row->{pozicija} } }, { $row->{name} => module_args( $row ) }; } return $page; @@ -225,15 +236,20 @@ } my $depth = $kat->{depth}; + if ( ! defined $pos[ $depth - 2 ] ) { + warn "FIXING CATEGORY: ",dump( $kat ); + $node->{class} = "error"; + $depth--; + } @pos = splice( @pos, 0, $depth ); $pos[ $depth - 1 ]++; - warn "## category depth = $depth pos = ",dump( @pos ); + warn "## category depth = $depth pos = ",dump( @pos ) if $debug; my $code = '$navigation'; map { $code .= '->[' . ( $_ - 1 ) . ']->{children}' } @pos; $code =~ s/->{children}$//; - warn "## category code: $code\n"; + warn "## category code: $code\n" if $debug; eval $code . '= $node'; if ( $@ ) { warn "SKIPPED CATEGORY: $@ ",dump( $kat ); @@ -267,10 +283,10 @@ my $ms_depth = $ms->{depth} + $depth; my $p = $pos[ $ms_depth - 1 ]++; - warn "## multistatic depth = $ms_depth pos = ",dump( @pos ); + warn "## multistatic depth = $ms_depth pos = ",dump( @pos ) if $debug; my $ms_code = $code . '->{children}->[ ' . $p . '] = $node'; - warn "## multistatic code: $ms_code\n"; + warn "## multistatic code: $ms_code\n" if $debug; eval $ms_code; if ( $@ ) { warn "SKIPPED MULTISTATIC: $@ ",dump( $ms );