ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.88 by root, Mon Jun 5 05:31:13 2006 UTC vs.
Revision 1.89 by root, Mon Jun 5 21:10:03 2006 UTC

24use utf8; 24use utf8;
25 25
26use Carp (); 26use Carp ();
27use AnyEvent (); 27use AnyEvent ();
28use BerkeleyDB; 28use BerkeleyDB;
29use Pod::POM; 29use Pod::POM ();
30use Storable (); # finally
31
32package CFClient::PodToPango;
33
34use base Pod::POM::View::Text;
35
36our $VERSION = 1; # bump if resultant formatting changes
37
38our $indent = 0;
39
40*view_seq_code =
41*view_seq_bold = sub { "<b>$_[1]</b>" };
42*view_seq_italic = sub { "<i>$_[1]</i>" };
43*view_seq_space =
44*view_seq_link =
45*view_seq_index = sub { CFClient::UI::Label::escape ($_[1]) };
46
47sub view_seq_text {
48 my $text = $_[1];
49 $text =~ s/\s+/ /g;
50 CFClient::UI::Label::escape ($text)
51}
52
53sub view_item {
54 ("\t" x ($indent / 4))
55 . $_[1]->title->present ($_[0])
56 . "\n"
57 . $_[1]->content->present ($_[0])
58}
59
60sub view_verbatim {
61 (join "",
62 map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n",
63 split /\n/, CFClient::UI::Label::escape ($_[1]))
64 . "\n"
65}
66
67sub view_textblock {
68 ("\t" x ($indent / 2)) . "$_[1]\n\n"
69}
70
71sub view_head1 {
72 "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
73 . $_[1]->content->present ($_[0])
74};
75
76sub view_head2 {
77 "\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
78 . $_[1]->content->present ($_[0])
79};
80
81sub view_head3 {
82 "\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
83 . $_[1]->content->present ($_[0])
84};
85
86sub view_over {
87 local $indent = $indent + $_[1]->indent;
88 $_[1]->content->present ($_[0])
89}
90
91package CFClient::Database;
92
93our @ISA = BerkeleyDB::Btree::;
94
95sub get($$) {
96 my $data;
97
98 $_[0]->db_get ($_[1], $data) == 0
99 ? $data
100 : ()
101}
102
103my %DB_SYNC;
104
105sub put($$$) {
106 my ($db, $key, $data) = @_;
107
108 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
109
110 $db->db_put ($key => $data)
111}
112
113package CFClient;
30 114
31sub find_rcfile($) { 115sub find_rcfile($) {
32 my $path; 116 my $path;
33 117
34 for (grep !ref, @INC) { 118 for (grep !ref, @INC) {
67 $::CFG->{VERSION} = $::VERSION; 151 $::CFG->{VERSION} = $::VERSION;
68 print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]); 152 print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]);
69 } 153 }
70 154
71 close CFG; 155 close CFG;
72}
73
74my %POD_CACHE;
75
76sub load_pod($) {
77 $POD_CACHE{$_[0]} ||= do {
78 my $pod = do {
79 local $/;
80 open my $pod, "<:utf8", $_[0]
81 or die "$_[0]: $!";
82 <$pod>
83 };
84
85 Pod::POM->new->parse_text ($pod)
86 }
87} 156}
88 157
89our $DB_ENV; 158our $DB_ENV;
90 159
91{ 160{
120 -Property => DB_CHKSUM, 189 -Property => DB_CHKSUM,
121 -Flags => DB_CREATE | DB_UPGRADE, 190 -Flags => DB_CREATE | DB_UPGRADE,
122 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 191 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
123} 192}
124 193
194my $pod_cache = db_table "pod_cache";
195
196sub load_pod($$$$) {
197 my ($path, $filtertype, $filterversion, $filtercb) = @_;
198
199 stat $path
200 or die "$path: $!";
201
202 my $phash = join ",", $filterversion, $CFClient::PodToPango::VERSION, (stat _)[7,9];
203
204 my ($chash, $pom) = eval { @{ Storable::thaw $pod_cache->get ("$path/$filtertype") } };
205
206 return $pom if $chash eq $phash;
207
208 my $pod = do {
209 local $/;
210 open my $pod, "<:utf8", $_[0]
211 or die "$_[0]: $!";
212 <$pod>
213 };
214
215 #utf8::downgrade $pod;
216
217 $pom = $filtercb-> (Pod::POM->new->parse_text ($pod));
218
219 $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]);
220
221 $pom
222}
223
125sub pod_to_pango($) { 224sub pod_to_pango($) {
126 my ($pom) = @_; 225 my ($pom) = @_;
127 226
128 $pom->present ("CFClient::PodToPango") 227 $pom->present ("CFClient::PodToPango")
129} 228}
133 232
134 [ 233 [
135 map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "], 234 map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "],
136 split /\n/, $pom->present ("CFClient::PodToPango") 235 split /\n/, $pom->present ("CFClient::PodToPango")
137 ] 236 ]
138}
139
140package CFClient::PodToPango;
141
142use base Pod::POM::View::Text;
143
144our $indent = 0;
145
146*view_seq_code =
147*view_seq_bold = sub { "<b>$_[1]</b>" };
148*view_seq_italic = sub { "<i>$_[1]</i>" };
149*view_seq_space =
150*view_seq_link =
151*view_seq_index = sub { CFClient::UI::Label::escape ($_[1]) };
152
153sub view_seq_text {
154 my $text = $_[1];
155 $text =~ s/\s+/ /g;
156 CFClient::UI::Label::escape ($text)
157}
158
159sub view_item {
160 ("\t" x ($indent / 4))
161 . $_[1]->title->present ($_[0])
162 . "\n"
163 . $_[1]->content->present ($_[0])
164}
165
166sub view_verbatim {
167 (join "",
168 map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n",
169 split /\n/, CFClient::UI::Label::escape ($_[1]))
170 . "\n"
171}
172
173sub view_textblock {
174 ("\t" x ($indent / 2)) . "$_[1]\n\n"
175}
176
177sub view_head1 {
178 "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
179 . $_[1]->content->present ($_[0])
180};
181
182sub view_head2 {
183 "\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
184 . $_[1]->content->present ($_[0])
185};
186
187sub view_head3 {
188 "\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
189 . $_[1]->content->present ($_[0])
190};
191
192sub view_over {
193 local $indent = $indent + $_[1]->indent;
194 $_[1]->content->present ($_[0])
195}
196
197package CFClient::Database;
198
199our @ISA = BerkeleyDB::Btree::;
200
201sub get($$) {
202 my $data;
203
204 $_[0]->db_get ($_[1], $data) == 0
205 ? $data
206 : ()
207}
208
209my %DB_SYNC;
210
211sub put($$$) {
212 my ($db, $key, $data) = @_;
213
214 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
215
216 $db->db_put ($key => $data)
217} 237}
218 238
219package CFClient::Item; 239package CFClient::Item;
220 240
221use strict; 241use strict;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines