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

Legend:
Removed from v.6  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26