/[webpac2]/Webpacus/lib/Webpacus/Model/Databases.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 /Webpacus/lib/Webpacus/Model/Databases.pm

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

revision 304 by dpavlin, Mon Dec 19 23:51:13 2005 UTC revision 349 by dpavlin, Sat Jan 7 17:34:21 2006 UTC
# Line 3  package Webpacus::Model::Databases; Line 3  package Webpacus::Model::Databases;
3  use strict;  use strict;
4  use warnings;  use warnings;
5  use base 'Catalyst::Model';  use base 'Catalyst::Model';
6  use Text::Iconv;  use Encode qw/decode/;
7    
8  =head1 NAME  =head1 NAME
9    
# Line 30  sub new { Line 30  sub new {
30                  $c->log->fail("didn't find databases in config");                  $c->log->fail("didn't find databases in config");
31          $self->{log} = $c->log;          $self->{log} = $c->log;
32    
33          my $from = $c->config->{config_encoding};          $c->log->debug("using config encoding ", $self->config->{config_encoding});
         my $to = $c->config->{catalyst_encoding};  
   
         $self->{iconv} = new Text::Iconv($from, $to) if ($from && $to);  
34    
35          return $self;          return $self;
36  }  }
37    
38  =head1 convert  =head1 convert
39    
40  Convert encodings from C<config_encoding> to C<catalyst_encoding>  Convert encodings from C<config_encoding>
41    
42    my $utf8 = $self->convert('foobar');    my $utf8 = $self->convert('foobar');
43    
# Line 49  Convert encodings from C<config_encoding Line 46  Convert encodings from C<config_encoding
46  sub convert {  sub convert {
47          my $self = shift;          my $self = shift;
48          my $val = shift || return;          my $val = shift || return;
49          return $val unless ($self->{iconv});          my $encoding = $self->config->{config_encoding} || return $val;
50            return decode($encoding, $val);
         return $self->{iconv}->convert($val);  
51  }  }
52    
53  =head1 list_inputs  =head1 list_inputs
# Line 91  sub list_inputs { Line 87  sub list_inputs {
87    
88  Returns just of just unique databases with C<name> and C<prefix>.  Returns just of just unique databases with C<name> and C<prefix>.
89    
90     my @dbs = $c->comp('Model::Databases')->list;
91    
92    You can also return just databases that have C<input> defined (that are not
93    empty databases used for agregation) if you add option C<require_input>.
94    
95     my @db_2 = $c->comp('Model::Databases')->list( require_input => 1 );
96    
97  =cut  =cut
98    
99  sub list {  sub list {
100          my $self = shift;          my $self = shift;
101    
102            my $args = shift;
103    
104          my @databases;          my @databases;
105    
106          foreach my $db (keys %{ $self->{databases} }) {          foreach my $db (keys %{ $self->{databases} }) {
107                  my $d = $self->{databases}->{$db} || die;                  my $d = $self->{databases}->{$db} || die;
108    
109                    if ($args->{require_input}) {
110                            next unless ($d->{input});
111                    }
112    
113                  my $el = {                  my $el = {
114                          name    => $self->convert( $d->{name} || $db ),                          name    => $self->convert( $d->{name} || $db ),
115                          prefix  => $self->convert( $db ),                          prefix  => $self->convert( $db ),

Legend:
Removed from v.304  
changed lines
  Added in v.349

  ViewVC Help
Powered by ViewVC 1.1.26