1 |
dpavlin |
1 |
package WebPAC::Input; |
2 |
|
|
|
3 |
|
|
use warnings; |
4 |
|
|
use strict; |
5 |
|
|
|
6 |
|
|
=head1 NAME |
7 |
|
|
|
8 |
dpavlin |
3 |
WebPAC::Input - core module for input file format |
9 |
dpavlin |
1 |
|
10 |
|
|
=head1 VERSION |
11 |
|
|
|
12 |
|
|
Version 0.01 |
13 |
|
|
|
14 |
|
|
=cut |
15 |
|
|
|
16 |
|
|
our $VERSION = '0.01'; |
17 |
|
|
|
18 |
|
|
=head1 SYNOPSIS |
19 |
|
|
|
20 |
dpavlin |
3 |
This module will load particular loader module and execute it's functions. |
21 |
dpavlin |
1 |
|
22 |
|
|
Perhaps a little code snippet. |
23 |
|
|
|
24 |
|
|
use WebPAC::Input; |
25 |
|
|
|
26 |
dpavlin |
3 |
my $db = WebPAC::Input->new( |
27 |
|
|
format => 'NULL', |
28 |
|
|
config => $config, |
29 |
dpavlin |
6 |
lookup => $lookup_obj, |
30 |
dpavlin |
3 |
); |
31 |
dpavlin |
1 |
|
32 |
dpavlin |
3 |
$db->open('/path/to/database'); |
33 |
|
|
print "database size: ",$db->size,"\n"; |
34 |
|
|
while (my $row = $db->fetch) { |
35 |
|
|
... |
36 |
|
|
} |
37 |
|
|
$db->close; |
38 |
dpavlin |
1 |
|
39 |
|
|
=head1 FUNCTIONS |
40 |
|
|
|
41 |
dpavlin |
3 |
=head2 new |
42 |
dpavlin |
1 |
|
43 |
dpavlin |
3 |
Create new input database object. |
44 |
|
|
|
45 |
dpavlin |
9 |
my $db = new WebPAC::Input( |
46 |
|
|
format => 'NULL' |
47 |
|
|
code_page => 'ISO-8859-2', |
48 |
|
|
); |
49 |
dpavlin |
3 |
|
50 |
dpavlin |
9 |
Optional parametar C<code_page> specify application code page (which will be |
51 |
|
|
used internally). This should probably be your terminal encoding, and by |
52 |
|
|
default, it C<ISO-8859-2>. |
53 |
|
|
|
54 |
dpavlin |
1 |
=cut |
55 |
|
|
|
56 |
dpavlin |
3 |
sub new { |
57 |
|
|
my $class = shift; |
58 |
|
|
my $self = {@_}; |
59 |
|
|
bless($self, $class); |
60 |
|
|
|
61 |
dpavlin |
9 |
$self->{'code_page'} ||= 'ISO-8859-2'; |
62 |
|
|
|
63 |
dpavlin |
3 |
$self ? return $self : return undef; |
64 |
dpavlin |
1 |
} |
65 |
|
|
|
66 |
dpavlin |
3 |
=head1 MEMORY USAGE |
67 |
dpavlin |
1 |
|
68 |
dpavlin |
3 |
C<low_mem> options is double-edged sword. If enabled, WebPAC |
69 |
|
|
will run on memory constraint machines (which doesn't have enough |
70 |
|
|
physical RAM to create memory structure for whole source database). |
71 |
dpavlin |
1 |
|
72 |
dpavlin |
3 |
If your machine has 512Mb or more of RAM and database is around 10000 records, |
73 |
|
|
memory shouldn't be an issue. If you don't have enough physical RAM, you |
74 |
|
|
might consider using virtual memory (if your operating system is handling it |
75 |
|
|
well, like on FreeBSD or Linux) instead of dropping to L<DBM::Deep> to handle |
76 |
|
|
parsed structure of ISIS database (this is what C<low_mem> option does). |
77 |
dpavlin |
1 |
|
78 |
dpavlin |
3 |
Hitting swap at end of reading source database is probably o.k. However, |
79 |
|
|
hitting swap before 90% will dramatically decrease performance and you will |
80 |
|
|
be better off with C<low_mem> and using rest of availble memory for |
81 |
|
|
operating system disk cache (Linux is particuallary good about this). |
82 |
|
|
However, every access to database record will require disk access, so |
83 |
|
|
generation phase will be slower 10-100 times. |
84 |
|
|
|
85 |
|
|
Parsed structures are essential - you just have option to trade RAM memory |
86 |
|
|
(which is fast) for disk space (which is slow). Be sure to have planty of |
87 |
|
|
disk space if you are using C<low_mem> and thus L<DBM::Deep>. |
88 |
|
|
|
89 |
|
|
However, when WebPAC is running on desktop machines (or laptops :-), it's |
90 |
|
|
highly undesireable for system to start swapping. Using C<low_mem> option can |
91 |
|
|
reduce WecPAC memory usage to around 64Mb for same database with lookup |
92 |
|
|
fields and sorted indexes which stay in RAM. Performance will suffer, but |
93 |
|
|
memory usage will really be minimal. It might be also more confortable to |
94 |
|
|
run WebPAC reniced on those machines. |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
=head1 AUTHOR |
98 |
|
|
|
99 |
|
|
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
100 |
|
|
|
101 |
dpavlin |
1 |
=head1 COPYRIGHT & LICENSE |
102 |
|
|
|
103 |
|
|
Copyright 2005 Dobrica Pavlinusic, All Rights Reserved. |
104 |
|
|
|
105 |
|
|
This program is free software; you can redistribute it and/or modify it |
106 |
|
|
under the same terms as Perl itself. |
107 |
|
|
|
108 |
|
|
=cut |
109 |
|
|
|
110 |
|
|
1; # End of WebPAC::Input |