/[suikacvs]/webroot/swe/lib/SWE/DB/SuikaWiki3.pm
Suika

Contents of /webroot/swe/lib/SWE/DB/SuikaWiki3.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Sat Nov 8 08:09:31 2008 UTC (16 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +3 -3 lines
++ swe/lib/SWE/DB/ChangeLog	8 Nov 2008 07:16:36 -0000
2008-11-08  Wakaba  <wakaba@suika.fam.cx>

	* SuikaWiki3.pm: Use euc-jp-sw encoding for compatibility with old
	data.

1 package SWE::DB::SuikaWiki3;
2 use strict;
3
4 require Encode::EUCJPSW;
5
6 sub new ($) {
7 my $self = bless {
8 ns_suffix => '.ns',
9 leaf_suffix => '.txt',
10 root_key => ['HomePage'],
11 root_directory_name => ',/',
12 }, shift;
13
14 return $self;
15 } # new
16
17 my $get_file_name = sub {
18 my $self = shift;
19 my $key = shift;
20 $key = $self->{root_key} if @$key == 0;
21
22 my $file_name = $self->{root_directory_name};
23 $file_name .= join '/',
24 map { s/(.)/sprintf '%02X', ord $1/sge; $_ . $self->{ns_suffix} }
25 map { Encode::encode ('euc-jp-sw', $_) } @$key;
26 $file_name =~ s/\Q$self->{ns_suffix}\E$/$self->{leaf_suffix}/;
27
28 return $file_name;
29 }; # $get_file_name
30
31 sub get_data ($$) {
32 my $self = shift;
33 my $file_name = $get_file_name->($self, $_[0]);
34
35 return undef unless -f $file_name;
36
37 open my $file, '<:encoding(euc-jp-sw)', $file_name
38 or die "$0: $file_name: $!";
39 local $/ = undef;
40 return scalar <$file>;
41 } # get_data
42
43 sub set_data ($$$) {
44
45 ## not implemented yet.
46
47 } # set_data
48
49 1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24