Annotation of openbsd/OpenBSDTorrents/lib/BT/MetaInfo/Cached.pm, Revision 1.4
1.4 ! andrew 1: # $Id: OBTMetaInfo.pm,v 1.3 2005/05/02 21:46:48 andrew Exp andrew $
1.2 andrew 2: use strict;
3:
1.1 andrew 4: package BT::OBTMetaInfo;
5:
6: require 5.6.0;
1.2 andrew 7: use vars qw( $VERSION @ISA );
1.1 andrew 8:
1.3 andrew 9: use Digest::SHA1 qw(sha1);
1.4 ! andrew 10: use YAML qw/ DumpFile LoadFile /;
1.3 andrew 11:
1.1 andrew 12: use BT::MetaInfo;
1.3 andrew 13: use base 'BT::MetaInfo';
1.1 andrew 14:
1.3 andrew 15: use OpenBSDTorrents;
16:
1.4 ! andrew 17: $VERSION = do { my @r = (q$Id: OBTMetaInfo.pm,v 1.3 2005/05/02 21:46:48 andrew Exp andrew $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
1.1 andrew 18:
19: sub new
20: {
1.4 ! andrew 21: my $class = shift;
! 22: my $file = shift;
! 23:
! 24: my $obj = (defined($file)) ? _load($file, @_) : {};
! 25: return(bless($obj, $class));
1.1 andrew 26: }
27:
1.4 ! andrew 28: sub _load {
! 29: my $file = shift;
! 30: my $meta_file = shift;
! 31: my $regen = shift;
! 32:
! 33: my $info;
! 34: if ($meta_file && ! $regen && -e $meta_file) {
! 35: $info = LoadFile($meta_file);
! 36: }
1.1 andrew 37:
1.4 ! andrew 38: unless ($info) {
! 39: $info = BT::MetaInfo::_load($file);
! 40: DumpFile($meta_file, $info) if $meta_file;
! 41: }
1.3 andrew 42:
1.4 ! andrew 43: return $info;
! 44: }
1.3 andrew 45:
1.4 ! andrew 46: #sub cached
! 47: #{
! 48: # my $self = shift;
! 49: # my $which_info = shift;
! 50: # my $file = shift;
! 51: # my @args = @_;
! 52: #
! 53: # if (@args) {
! 54: # return $self->$which_info(@args),
! 55: # }
! 56: #
! 57: # return undef unless $which_info;
! 58: # return $self->$which_info unless $file;
! 59: #
! 60: # my $info = undef;
! 61: #
! 62: # if (-e $file) {
! 63: # #print "Reading meta file: $file\n";
! 64: # $info = LoadFile($file);
! 65: # }
! 66: #
! 67: # unless ($info->{$which_info}) {
! 68: # my $cur_info = $self->$which_info;
! 69: #
! 70: # $info->{$which_info} = $cur_info;
! 71: # DumpFile($file, $info);
! 72: # }
! 73: #
! 74: # if (defined $info->{$which_info}) {
! 75: # return $info->{$which_info};
! 76: # } else {
! 77: # return $self->$which_info;
! 78: # }
! 79: #}
1.1 andrew 80:
1.2 andrew 81: 1
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>