package Favorites;
use Common;
@ISA = qw(Common);
#公開したいサブルーチン
#@EXPORT = qw();
use strict;
use warnings;
use Utils;
use JFile;
sub new {
my ($module, $path) = @_;
my $self = {}; # 連想配列のリファレンスの作製
$self->{PATH} = $path;
$self->{URL} = undef; # 値を未定義にする
$self->{TITLE} = undef;
$self->{MEMO} = [];
# bless関数により、リファレンスされているものをパッケージに結びつける
bless($self);
$self->Read() if($path);
return $self; # リファレンスオブジェクトを返す
}
sub Favorite { return shift->{FAVORITE}; }
sub URL { return shift->{URL}; }
sub Title { return shift->{TITLE}; }
sub Read
{
my ($this, $path) = @_;
$path = $this->{PATH} if(!defined $path);
my $in = new JFile;
if(!$in->Open($path, "r")) {
print "Error in Favorites::Read: Can not read [$path].\n";
return 0;
}
my $favorite = $path;
my $urlstr;
$favorite =~ s/\.url$//i;
my $EUCPath = $path;
#print "path1: $path
\n";
Jcode::convert(\$EUCPath, "euc");
my ($drive, $directory, $filename, $ext, $lastdir, $filebody)
= Deps::SplitFilePath($EUCPath);
Jcode::convert(\$filebody, Deps::OSCharCode());
#print "path2: $filebody
\n";
my $title = $filebody;
$in->rewind();
while(1) {
my $line = $in->ReadLine();
last if(!defined $line);
Utils::DelSpace($line);
#print "l: [$line]\n";
if($line =~ /^URL=(.+)$/i) {
$urlstr = $1;
}
elsif($line =~ /^TITLE=(.+)$/i) {
$title = $1;
}
}
$in->Close();
$this->{FAVORITE} = $favorite;
$this->{URL} = $urlstr;
$this->{TITLE} = $title;
return 1;
}
sub url {
my $self = shift;
# 引数が残っていれば、URLデータをオブジェクトに格納する
if(@_) {
$self->{URL} = shift;
}
return $self->{URL};
}
sub title {
my $self = shift;
if(@_) {
$self->{TITLE} = shift;
}
return $self->{TITLE};
}
sub memo {
my $self = shift;
if(@_) {
@{ $self->{MEMO} } = @_;
}
return @{ $self->{MEMO} };
}
1;