/[webpac2]/trunk/lib/WebPAC/Input.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 /trunk/lib/WebPAC/Input.pm

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

revision 9 by dpavlin, Sat Jul 16 17:14:43 2005 UTC revision 10 by dpavlin, Sat Jul 16 20:35:30 2005 UTC
# Line 27  Perhaps a little code snippet. Line 27  Perhaps a little code snippet.
27          format => 'NULL',          format => 'NULL',
28          config => $config,          config => $config,
29          lookup => $lookup_obj,          lookup => $lookup_obj,
30            low_mem => 1,
31      );      );
32    
33      $db->open('/path/to/database');      $db->open('/path/to/database');
# Line 45  Create new input database object. Line 46  Create new input database object.
46    my $db = new WebPAC::Input(    my $db = new WebPAC::Input(
47          format => 'NULL'          format => 'NULL'
48          code_page => 'ISO-8859-2',          code_page => 'ISO-8859-2',
49            low_mem => 1,
50    );    );
51    
52  Optional parametar C<code_page> specify application code page (which will be  Optional parametar C<code_page> specify application code page (which will be
53  used internally). This should probably be your terminal encoding, and by  used internally). This should probably be your terminal encoding, and by
54  default, it C<ISO-8859-2>.  default, it C<ISO-8859-2>.
55    
56    Default is not to use C<low_mem> options (see L<MEMORY USAGE> below).
57    
58  =cut  =cut
59    
60  sub new {  sub new {
# Line 60  sub new { Line 64  sub new {
64    
65          $self->{'code_page'} ||= 'ISO-8859-2';          $self->{'code_page'} ||= 'ISO-8859-2';
66    
67            my $log = $self->_get_logger;
68    
69            # running with low_mem flag? well, use DBM::Deep then.
70            if ($self->{'low_mem'}) {
71                    $log->info("running with low_mem which impacts performance (<32 Mb memory usage)");
72    
73                    my $db_file = "data.db";
74    
75                    if (-e $db_file) {
76                            unlink $db_file or $log->logdie("can't remove '$db_file' from last run");
77                            $log->debug("removed '$db_file' from last run");
78                    }
79    
80                    require DBM::Deep;
81    
82                    my $db = new DBM::Deep $db_file;
83    
84                    $log->logdie("DBM::Deep error: $!") unless ($db);
85    
86                    if ($db->error()) {
87                            $log->logdie("can't open '$db_file' under low_mem: ",$db->error());
88                    } else {
89                            $log->debug("using file '$db_file' for DBM::Deep");
90                    }
91    
92                    $self->{'db'} = $db;
93            }
94    
95          $self ? return $self : return undef;          $self ? return $self : return undef;
96  }  }
97    

Legend:
Removed from v.9  
changed lines
  Added in v.10

  ViewVC Help
Powered by ViewVC 1.1.26