/[A3C]/lib/Strix.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Strix.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 171 by dpavlin, Mon Jun 16 13:16:57 2008 UTC revision 174 by dpavlin, Mon Jun 16 16:48:16 2008 UTC
# Line 4  use strict; Line 4  use strict;
4  use warnings;  use warnings;
5    
6  use base qw(Jifty::Object Class::Accessor::Fast);  use base qw(Jifty::Object Class::Accessor::Fast);
7  __PACKAGE__->mk_accessors( qw(site uid) );  __PACKAGE__->mk_accessors( qw(instance uid) );
8    
9  use DBI;  use DBI;
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
# Line 20  Strix Line 20  Strix
20    
21  =head2 new  =head2 new
22    
23    my $strix = Strix->new({ site => 'os-test0604-zg' });    my $strix = Strix->new({ instance => 'os-test0604-zg' });
24    
25  =head2 dbh  =head2 dbh
26    
27    my $dbh = Strix->dbh( $site_name );    my $dbh = Strix->dbh( $strix_instance );
28    
29    my $dbh = $strix->dbh;    my $dbh = $strix->dbh;
30    
31  =cut  =cut
32    
33  our $site_dbh;  our $instance_dbh;
34    
35  sub dbh {  sub dbh {
36          my $self = shift;          my $self = shift;
37    
38          my $site = shift || $self->site || confess "no site";          my $instance = shift || $self->instance || confess "no instance";
39    
40          return $site_dbh->{$site} if $site_dbh->{$site};          return $instance_dbh->{$instance} if $instance_dbh->{$instance};
41    
42          my $config = Jifty->config->app('strix') or die "need strix config";          my $config = Jifty->config->app('strix') or die "need strix config";
43          my $database = $config->{database} or die "no strix.database in config";          my $database = $config->{database} or die "no strix.database in config";
# Line 45  sub dbh { Line 45  sub dbh {
45          Jifty->log->debug("using config ", dump( $database ));          Jifty->log->debug("using config ", dump( $database ));
46    
47          my $dsn =          my $dsn =
48                  'DBI:Pg:dbname=' . $site .                  'DBI:Pg:dbname=' . $instance .
49                  ';host=' . $database->{host} .                  ';host=' . $database->{host} .
50                  ';port=' . $database->{port};                  ';port=' . $database->{port};
51    
52          Jifty->log->info("Connect to site $site with dsn $dsn");          Jifty->log->info("Connect to instance $instance with dsn $dsn");
53    
54          my $dbh = DBI->connect( $dsn, $database->{user}, $database->{passwd} ) or die $DBI::errstr;          my $dbh = DBI->connect( $dsn, $database->{user}, $database->{passwd} ) or die $DBI::errstr;
55    
56          $site_dbh->{$site} = $dbh;          $instance_dbh->{$instance} = $dbh;
57    
58          warn "## site_dbh = ",dump( $site_dbh );          warn "## instance_dbh = ",dump( $instance_dbh ) if $debug;
59    
60          return $dbh;          return $dbh;
61  }  }
# Line 116  sub layout { Line 116  sub layout {
116          });          });
117          $sth->execute( $category->{template_id} );          $sth->execute( $category->{template_id} );
118    
119            sub module_args {
120                    my $row = shift;
121                    return undef unless $row->{module_args};
122                    my $args;
123                    foreach my $a ( split(/\&/, $row->{module_args} ) ) {
124                            $args->{$1} = $2 if $a =~ m/^(.+)=(.+)$/;
125                    }
126                    return $args;
127            }
128    
129          while (my $row = $sth->fetchrow_hashref() ) {          while (my $row = $sth->fetchrow_hashref() ) {
130                  warn dump( $row ) if $debug;                  warn dump( $row ) if $debug;
131                  push @{ $page->{free} }, { $row->{name} => $row->{module_args} };                  push @{ $page->{free} }, { $row->{name} => module_args( $row ) };
132          }          }
133    
134          warn "### pre layout...\n" if $debug;          warn "### pre layout...\n" if $debug;
# Line 138  sub layout { Line 148  sub layout {
148    
149          while (my $row = $sth->fetchrow_hashref() ) {          while (my $row = $sth->fetchrow_hashref() ) {
150                  warn dump( $row ) if $debug;                  warn dump( $row ) if $debug;
151                  push @{ $page->{pre}->{ $row->{pos} } }, { $row->{name} => $row->{module_args} };                  push @{ $page->{pre}->{ $row->{pos} } }, { $row->{name} => module_args( $row ) };
152          }          }
153    
154          warn "### post layout...\n" if $debug;          warn "### post layout...\n" if $debug;
# Line 153  sub layout { Line 163  sub layout {
163    
164          while (my $row = $sth->fetchrow_hashref() ) {          while (my $row = $sth->fetchrow_hashref() ) {
165                  warn dump( $row ) if $debug;                  warn dump( $row ) if $debug;
166                  push @{ $page->{post}->{ $row->{pozicija} } }, { $row->{name} => $row->{module_args} };                  push @{ $page->{post}->{ $row->{pozicija} } }, { $row->{name} => module_args( $row ) };
167          }          }
168    
169          return $page;          return $page;
# Line 228  sub site_navigation { Line 238  sub site_navigation {
238                  @pos = splice( @pos, 0, $depth );                  @pos = splice( @pos, 0, $depth );
239                  $pos[ $depth - 1 ]++;                  $pos[ $depth - 1 ]++;
240    
241                  warn "## category depth = $depth pos = ",dump( @pos );                  warn "## category depth = $depth pos = ",dump( @pos ) if $debug;
242    
243                  my $code = '$navigation';                  my $code = '$navigation';
244                  map { $code .= '->[' . ( $_ - 1 ) . ']->{children}' } @pos;                  map { $code .= '->[' . ( $_ - 1 ) . ']->{children}' } @pos;
245                  $code =~ s/->{children}$//;                  $code =~ s/->{children}$//;
246                  warn "## category code: $code\n";                  warn "## category code: $code\n" if $debug;
247                  eval $code . '= $node';                  eval $code . '= $node';
248                  if ( $@ ) {                  if ( $@ ) {
249                          warn "SKIPPED CATEGORY: $@ ",dump( $kat );                          warn "SKIPPED CATEGORY: $@ ",dump( $kat );
# Line 267  sub site_navigation { Line 277  sub site_navigation {
277                                                                    
278                                  my $ms_depth = $ms->{depth} + $depth;                                  my $ms_depth = $ms->{depth} + $depth;
279                                  my $p = $pos[ $ms_depth - 1 ]++;                                  my $p = $pos[ $ms_depth - 1 ]++;
280                                  warn "## multistatic depth = $ms_depth pos = ",dump( @pos );                                  warn "## multistatic depth = $ms_depth pos = ",dump( @pos ) if $debug;
281    
282                                  my $ms_code = $code . '->{children}->[ ' . $p . ']  = $node';                                  my $ms_code = $code . '->{children}->[ ' . $p . ']  = $node';
283                                  warn "## multistatic code: $ms_code\n";                                  warn "## multistatic code: $ms_code\n" if $debug;
284                                  eval $ms_code;                                  eval $ms_code;
285                                  if ( $@ ) {                                  if ( $@ ) {
286                                          warn "SKIPPED MULTISTATIC: $@ ",dump( $ms );                                          warn "SKIPPED MULTISTATIC: $@ ",dump( $ms );

Legend:
Removed from v.171  
changed lines
  Added in v.174

  ViewVC Help
Powered by ViewVC 1.1.26