--- deliantra/Deliantra-Client/DC.pm 2006/06/05 05:23:19 1.87
+++ deliantra/Deliantra-Client/DC.pm 2006/06/18 17:13:10 1.93
@@ -26,7 +26,92 @@
use Carp ();
use AnyEvent ();
use BerkeleyDB;
-use Pod::POM;
+use Pod::POM ();
+use Scalar::Util ();
+use Storable (); # finally
+
+package CFClient::PodToPango;
+
+use base Pod::POM::View::Text;
+
+our $VERSION = 1; # bump if resultant formatting changes
+
+our $indent = 0;
+
+*view_seq_code =
+*view_seq_bold = sub { "$_[1]" };
+*view_seq_italic = sub { "$_[1]" };
+*view_seq_space =
+*view_seq_link =
+*view_seq_index = sub { CFClient::UI::Label::escape ($_[1]) };
+
+sub view_seq_text {
+ my $text = $_[1];
+ $text =~ s/\s+/ /g;
+ CFClient::UI::Label::escape ($text)
+}
+
+sub view_item {
+ ("\t" x ($indent / 4))
+ . $_[1]->title->present ($_[0])
+ . "\n\n"
+ . $_[1]->content->present ($_[0])
+}
+
+sub view_verbatim {
+ (join "",
+ map +("\t" x ($indent / 2)) . "$_\n",
+ split /\n/, CFClient::UI::Label::escape ($_[1]))
+ . "\n"
+}
+
+sub view_textblock {
+ ("\t" x ($indent / 2)) . "$_[1]\n\n"
+}
+
+sub view_head1 {
+ "\n\n" . $_[1]->title->present ($_[0]) . "\n\n"
+ . $_[1]->content->present ($_[0])
+};
+
+sub view_head2 {
+ "\n" . $_[1]->title->present ($_[0]) . "\n\n"
+ . $_[1]->content->present ($_[0])
+};
+
+sub view_head3 {
+ "\n" . $_[1]->title->present ($_[0]) . "\n\n"
+ . $_[1]->content->present ($_[0])
+};
+
+sub view_over {
+ local $indent = $indent + $_[1]->indent;
+ $_[1]->content->present ($_[0])
+}
+
+package CFClient::Database;
+
+our @ISA = BerkeleyDB::Btree::;
+
+sub get($$) {
+ my $data;
+
+ $_[0]->db_get ($_[1], $data) == 0
+ ? $data
+ : ()
+}
+
+my %DB_SYNC;
+
+sub put($$$) {
+ my ($db, $key, $data) = @_;
+
+ $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
+
+ $db->db_put ($key => $data)
+}
+
+package CFClient;
sub find_rcfile($) {
my $path;
@@ -71,17 +156,6 @@
close CFG;
}
-sub load_pod($) {
- my $pod = do {
- local $/;
- open my $pod, "<:utf8", $_[0]
- or die "$_[0]: $!";
- <$pod>
- };
-
- Pod::POM->new->parse_text ($pod);
-}
-
our $DB_ENV;
{
@@ -118,98 +192,49 @@
or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
}
-sub pod_to_pango($) {
- my ($pom) = @_;
+my $pod_cache = db_table "pod_cache";
- $pom->present ("CFClient::PodToPango")
-}
+sub load_pod($$$$) {
+ my ($path, $filtertype, $filterversion, $filtercb) = @_;
-sub pod_to_pango_list($) {
- my ($pom) = @_;
-
- [
- map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "],
- split /\n/, $pom->present ("CFClient::PodToPango")
- ]
-}
-
-package CFClient::PodToPango;
-
-use base Pod::POM::View::Text;
+ stat $path
+ or die "$path: $!";
-our $indent = 0;
-
-*view_seq_code =
-*view_seq_bold = sub { "$_[1]" };
-*view_seq_italic = sub { "$_[1]" };
-*view_seq_space =
-*view_seq_link =
-*view_seq_index = sub { CFClient::UI::Label::escape ($_[1]) };
-
-sub view_seq_text {
- my $text = $_[1];
- $text =~ s/\s+/ /g;
- CFClient::UI::Label::escape ($text)
-}
+ my $phash = join ",", $filterversion, $CFClient::PodToPango::VERSION, (stat _)[7,9];
-sub view_item {
- ("\t" x ($indent / 4))
- . $_[1]->title->present ($_[0])
- . "\n"
- . $_[1]->content->present ($_[0])
-}
+ my ($chash, $pom) = eval { @{ Storable::thaw $pod_cache->get ("$path/$filtertype") } };
-sub view_verbatim {
- (join "",
- map +("\t" x ($indent / 2)) . "$_\n",
- split /\n/, CFClient::UI::Label::escape ($_[1]))
- . "\n"
-}
+ return $pom if $chash eq $phash;
-sub view_textblock {
- ("\t" x ($indent / 2)) . "$_[1]\n\n"
-}
+ my $pod = do {
+ local $/;
+ open my $pod, "<:utf8", $_[0]
+ or die "$_[0]: $!";
+ <$pod>
+ };
-sub view_head1 {
- "\n\n" . $_[1]->title->present ($_[0]) . "\n\n"
- . $_[1]->content->present ($_[0])
-};
+ #utf8::downgrade $pod;
-sub view_head2 {
- "\n" . $_[1]->title->present ($_[0]) . "\n\n"
- . $_[1]->content->present ($_[0])
-};
+ $pom = $filtercb-> (Pod::POM->new->parse_text ($pod));
-sub view_head3 {
- "\n" . $_[1]->title->present ($_[0]) . "\n\n"
- . $_[1]->content->present ($_[0])
-};
+ $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]);
-sub view_over {
- local $indent = $indent + $_[1]->indent;
- $_[1]->content->present ($_[0])
+ $pom
}
-package CFClient::Database;
-
-our @ISA = BerkeleyDB::Btree::;
-
-sub get($$) {
- my $data;
+sub pod_to_pango($) {
+ my ($pom) = @_;
- $_[0]->db_get ($_[1], $data) == 0
- ? $data
- : ()
+ $pom->present ("CFClient::PodToPango")
}
-my %DB_SYNC;
-
-sub put($$$) {
- my ($db, $key, $data) = @_;
-
- $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
+sub pod_to_pango_list($) {
+ my ($pom) = @_;
- $db->db_put ($key => $data)
+ [
+ map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "],
+ split /\n/, $pom->present ("CFClient::PodToPango")
+ ]
}
package CFClient::Item;
@@ -269,7 +294,7 @@
$w = undef;
}
);
- $entry->focus_in;
+ $entry->grab_focus;
$w->show;
}
@@ -277,6 +302,9 @@
sub update_widgets {
my ($self) = @_;
+ # necessary to avoid cyclic references
+ Scalar::Util::weaken $self;
+
my $button_cb = sub {
my (undef, $ev, $x, $y) = @_;
@@ -462,14 +490,14 @@
return;
}
- $entry->focus_out;
+ $entry->grab_focus;
$cb->($mod, $sym);
$w->destroy
});
- $entry->focus_in;
+ $entry->grab_focus;
$w->show;
}
@@ -485,47 +513,6 @@
return $mods . CFClient::SDL_GetKeyName ($sym);
}
-package CFClient::Pickup;
-# some pickup constants
-sub PU_NOTHING { 0x00000000 }
-
-sub PU_DEBUG { 0x10000000 }
-sub PU_INHIBIT { 0x20000000 }
-sub PU_STOP { 0x40000000 }
-sub PU_NEWMODE { 0x80000000 }
-
-sub PU_RATIO { 0x0000000F }
-
-sub PU_FOOD { 0x00000010 }
-sub PU_DRINK { 0x00000020 }
-sub PU_VALUABLES { 0x00000040 }
-sub PU_BOW { 0x00000080 }
-
-sub PU_ARROW { 0x00000100 }
-sub PU_HELMET { 0x00000200 }
-sub PU_SHIELD { 0x00000400 }
-sub PU_ARMOUR { 0x00000800 }
-
-sub PU_BOOTS { 0x00001000 }
-sub PU_GLOVES { 0x00002000 }
-sub PU_CLOAK { 0x00004000 }
-sub PU_KEY { 0x00008000 }
-
-sub PU_MISSILEWEAPON { 0x00010000 }
-sub PU_ALLWEAPON { 0x00020000 }
-sub PU_MAGICAL { 0x00040000 }
-sub PU_POTION { 0x00080000 }
-
-sub PU_SPELLBOOK { 0x00100000 }
-sub PU_SKILLSCROLL { 0x00200000 }
-sub PU_READABLES { 0x00400000 }
-sub PU_MAGIC_DEVICE { 0x00800000 }
-
-sub PU_NOT_CURSED { 0x01000000 }
-
-sub PU_JEWELS { 0x02000000 }
-
-
1;
=back