亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? counterfile.pm

?? ARM上的如果你對底層感興趣
?? PM
字號:
# This -*-perl -*- module implements a persistent counter class.
#
# $Id: CounterFile.pm,v 0.9 1996/10/31 09:38:57 aas Exp $
#

package File::CounterFile;


=head1 NAME

File::CounterFile - Persistent counter class

=head1 SYNOPSIS

 use File::CounterFile;
 $c = new File::CounterFile "COUNTER", "aa00";

 $id = $c->inc;
 open(F, ">F$id");

=head1 DESCRIPTION

This module implements a persistent counter class.  Each counter is
represented by a separate file in the file system.  File locking is
applied, so multiple processes might try to access the same counters
at the same time without risk of counter destruction.

You give the file name as the first parameter to the object
constructor (C<new>).  The file is created if it does not exist.

If the file name does not start with "/" or ".", then it is
interpreted as a file relative to C<$File::CounterFile::DEFAULT_DIR>.
The default value for this variable is initialized from the
environment variable C<TMPDIR>, or F</usr/tmp> is no environment
variable is defined.  You may want to assign a different value to this
variable before creating counters.

If you pass a second parameter to the constructor, that sets the
initial value for a new counter.  This parameter only takes effect
when the file is created (i.e. it does not exist before the call).

When you call the C<inc()> method, you increment the counter value by
one. When you call C<dec()> the counter value is decrementd.  In both
cases the new value is returned.  The C<dec()> method only works for
numerical counters (digits only).

You can peek at the value of the counter (without incrementing it) by
using the C<value()> method.

The counter can be locked and unlocked with the C<lock()> and
C<unlock()> methods.  Incrementing and value retrieval is faster when
the counter is locked, because we do not have to update the counter
file all the time.  You can query whether the counter is locked with
the C<locked()> method.

There is also an operator overloading interface to the
File::CounterFile object.  This means that you might use the C<++>
operator for incrementing the counter, C<--> operator for decrementing
and you can interpolate counters diretly into strings.

=head1 BUGS

It uses flock(2) to lock the counter file.  This does not work on all
systems.  Perhaps we should use the File::Lock module?

=head1 INSTALLATION

Copy this file to the F<File> subdirectory of your Perl 5 library
directory (often F</usr/local/lib/perl5>).

=head1 COPYRIGHT

Copyright (c) 1995-1996 Gisle Aas. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 AUTHOR

Gisle Aas <aas@sn.no>

=cut

require 5.002;
use Carp   qw(croak);
use Symbol qw(gensym);

sub Version { $VERSION; }
$VERSION = sprintf("%d.%02d", q$Revision: 0.9 $ =~ /(\d+)\.(\d+)/);

$MAGIC           = "#COUNTER-1.0\n";   # first line in counter files
$DEFAULT_INITIAL = 0;                  # default initial counter value

 # default location for counter files
$DEFAULT_DIR     = $ENV{TMPDIR} || "/usr/tmp";

# Experimental overloading.
%OVERLOAD = ('++'     => \&inc,
	     '--'     => \&dec,
	     '""'     => \&value,
	     fallback => 1,
);


sub new
{
    my($class, $file, $initial) = @_;
    croak "No file specified\n" unless defined $file;

    $file = "$DEFAULT_DIR/$file" unless $file =~ /^[\.\/]/;
    $initial = $DEFAULT_INITIAL unless defined $initial;

    my $value;
    if (-e $file) {
	croak "Specified file is a directory" if -d _;
	open(F, $file) or croak "Can't open $file: $!";
	local($/) = "\n";
	my $first_line = <F>;
	$value = <F>;
	close(F);
	croak "Bad counter magic '$first_line' in $file" unless $first_line eq $MAGIC;
	chomp($value);
    } else {
	open(F, ">$file") or croak "Can't create $file: $!";
	print F $MAGIC;
	print F $initial, "\n";
	close(F);
	$value = $initial;
    }

    bless { file    => $file,  # the filename for the counter
	    value   => $value, # the current value
	    updated => 0,      # flag indicating if value has changed
	    # handle => XXX,   # file handle symbol. Only present when locked
	  };
}


sub locked
{
    exists shift->{handle};
}


sub lock
{
    my($self) = @_;
    $self->unlock if $self->locked;

    my $fh = gensym();
    my $file = $self->{file};

    open($fh, "+<$file") or croak "Can't open $file: $!";
    flock($fh, 2) or croak "Can't flock: $!";  # 2 = exlusive lock

    local($/) = "\n";
    my $magic = <$fh>;
    if ($magic ne $MAGIC) {
	$self->unlock;
	croak("Bad counter magic '$magic' in $file");
    }
    chomp($self->{value} = <$fh>);

    $self->{handle}  = $fh;
    $self->{updated} = 0;
    $self;
}


sub unlock
{
    my($self) = @_;
    return unless $self->locked;

    my $fh = $self->{handle};

    if ($self->{updated}) {
	# write back new value
	seek($fh, 0, 0) or croak "Can't seek to beginning: $!";
	print $fh $MAGIC;
	print $fh "$self->{value}\n";
    }

    close($fh) or warn "Can't close: $!";
    delete $self->{handle};
    $self;
}


sub inc
{
    my($self) = @_;

    if ($self->locked) {
	$self->{value}++;
	$self->{updated} = 1;
    } else {
	$self->lock;
	$self->{value}++;
	$self->{updated} = 1;
	$self->unlock;
    }
    $self->{value}; # return value
}


sub dec
{
    my($self) = @_;

    if ($self->locked) {
	croak "Autodecrement is not magical in perl"
	    unless $self->{value} =~ /^\d+$/;
	$self->{value}--;
	$self->{updated} = 1;
    } else {
	$self->lock;
	croak "Autodecrement is not magical in perl"
	    unless $self->{value} =~ /^\d+$/;
	$self->{value}--;
	$self->{updated} = 1;
	$self->unlock;
    }
    $self->{value}; # return value
}


sub value
{
    my($self) = @_;
    my $value;
    if ($self->locked) {
	$value = $self->{value};
    } else {
	$self->lock;
	$value = $self->{value};
	$self->unlock;
    }
    $value;
}


sub DESTROY
{
    my $self = shift;
    $self->unlock;
}

####################################################################
#
# S E L F   T E S T   S E C T I O N
#
#####################################################################
#
# If we're not use'd or require'd execute self-test.
#
# Test is kept behind __END__ so it doesn't take uptime
# and memory  unless explicitly required. If you're working
# on the code you might find it easier to comment out the
# eval and __END__ so that error line numbers make more sense.

package main;

eval join('',<DATA>) || die $@ unless caller();

1;

__END__


$cf = "./zz-counter-$$";  # the name for out temprary counter

# Test normal object creation and increment

$c = new File::CounterFile $cf;

$id1 = $c->inc;
$id2 = $c->inc;

$c = new File::CounterFile $cf;
$id3 = $c->inc;
$id4 = $c->dec;

die "test failed" unless ($id1 == 1 && $id2 == 2 && $id3 == 3 && $id4 == 2);
unlink $cf;

# Test magic increment

$id1 = (new File::CounterFile $cf, "aa98")->inc;
$id2 = (new File::CounterFile $cf)->inc;
$id3 = (new File::CounterFile $cf)->inc;

eval {
    # This should now work because "Decrement is not magical in perl"
    $c = new File::CounterFile $cf; $id4 = $c->dec; $c = undef;
};
die "test failed (No exception to catch)" unless $@;

#print "$id1 $id2 $id3\n";

die "test failed" unless ($id1 eq "aa99" && $id2 eq "ab00" && $id3 eq "ab01");
unlink $cf;

# Test operator overloading

$c = new File::CounterFile $cf, "100";

$c->lock;

$c++;  # counter is now 101
$c++;  # counter is now 102
$c++;  # counter is now 103
$c--;  # counter is now 102 again

$id1 = "$c";
$id2 = ++$c;

$c = undef;  # destroy object

unlink $cf;

die "test failed" unless $id1 == 102 && $id2 == 103;


print "Selftest for File::CounterFile $File::CounterFile::VERSION ok\n";

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲成在人线免费| 欧美日韩第一区日日骚| 久久精品国产亚洲一区二区三区| 亚洲精品高清在线| 亚洲免费在线看| 亚洲欧洲av在线| 亚洲天堂成人在线观看| 亚洲伦理在线精品| 亚洲影院在线观看| 亚洲sss视频在线视频| 亚洲成年人影院| 婷婷成人激情在线网| 秋霞国产午夜精品免费视频| 免费日韩伦理电影| 国产精品自拍在线| av在线一区二区三区| 色婷婷国产精品| 69堂亚洲精品首页| 久久久久亚洲综合| 亚洲同性同志一二三专区| 亚洲一区在线观看视频| 日韩av一级电影| 国产.欧美.日韩| 91成人免费在线视频| 日韩欧美一卡二卡| 国产精品午夜久久| 亚洲午夜免费福利视频| 麻豆91在线播放| av综合在线播放| 欧美一卡二卡三卡| 欧美国产丝袜视频| 天堂久久久久va久久久久| 国产精品夜夜嗨| 91麻豆免费观看| 精品欧美一区二区久久| **网站欧美大片在线观看| 日韩国产成人精品| 91免费看`日韩一区二区| 日韩一区二区精品在线观看| 亚洲欧洲三级电影| 秋霞av亚洲一区二区三| 99re这里只有精品首页| 欧美成人一区二区三区在线观看 | 精品一二三四区| 91性感美女视频| 精品奇米国产一区二区三区| 亚洲一区二区欧美激情| 国产精品18久久久| 日韩一级二级三级| 亚洲国产日日夜夜| 91偷拍与自偷拍精品| 久久久久久久久久久久久女国产乱 | 国产综合色产在线精品| 欧洲一区在线观看| 一区视频在线播放| 国产大陆精品国产| 精品国产电影一区二区| 日本aⅴ免费视频一区二区三区| 色吊一区二区三区| 国产精品妹子av| 成人午夜免费av| 久久精品日产第一区二区三区高清版| 日韩一区精品视频| 欧美日韩一区国产| 夜夜亚洲天天久久| 91久久线看在观草草青青| 国产精品久久久久国产精品日日 | 97久久超碰国产精品| 欧美大片免费久久精品三p | 久久精品国产一区二区| 91麻豆精品国产自产在线| 亚洲综合一区在线| 欧美亚洲一区三区| 一区二区三区四区在线免费观看| 91免费观看在线| 一级女性全黄久久生活片免费| 91视频在线观看免费| 1024国产精品| 欧美日韩视频专区在线播放| 亚洲综合激情网| 欧美日韩免费视频| 青青草国产精品97视觉盛宴| 欧美一级片在线看| 久久99国产精品成人| 久久久久久久久久电影| 丁香六月综合激情| 亚洲啪啪综合av一区二区三区| 91免费版在线| 爽爽淫人综合网网站| 日韩一卡二卡三卡| 国产大片一区二区| 一区二区三区四区蜜桃| 欧美老肥妇做.爰bbww视频| 免费欧美高清视频| 中文字幕国产一区| 91九色02白丝porn| 九九热在线视频观看这里只有精品| 久久午夜羞羞影院免费观看| 成人免费毛片aaaaa**| 亚洲美女免费在线| 日韩欧美国产1| 99re6这里只有精品视频在线观看 99re8在线精品视频免费播放 | 精品成人a区在线观看| 从欧美一区二区三区| 一区二区三区视频在线观看| 欧美年轻男男videosbes| 国产精品综合网| 一区二区免费视频| 精品粉嫩超白一线天av| 91在线观看高清| 秋霞成人午夜伦在线观看| 中文字幕永久在线不卡| 日韩一本二本av| 色哦色哦哦色天天综合| 久久精品国产免费| 亚洲一区自拍偷拍| 国产精品久久久久7777按摩| 9191国产精品| 91成人免费在线视频| 国产成人福利片| 久久国内精品视频| 亚洲电影第三页| 国产精品美女www爽爽爽| 欧美高清dvd| 在线欧美一区二区| 粉嫩欧美一区二区三区高清影视| 午夜久久久影院| 中文字幕在线不卡| 国产欧美日韩激情| 欧美v日韩v国产v| 在线成人免费视频| 色婷婷综合激情| 成人短视频下载 | 国产精品亲子伦对白| 欧美一区二区成人| 91同城在线观看| 99视频在线观看一区三区| 国产又粗又猛又爽又黄91精品| 亚洲国产精品自拍| 一区二区三区免费| 亚洲欧美自拍偷拍色图| 国产欧美va欧美不卡在线| 亚洲精品一区二区三区蜜桃下载 | 婷婷久久综合九色国产成人| 亚洲柠檬福利资源导航| 国产精品美日韩| 中文字幕一区二区在线播放| 国产精品五月天| 亚洲日本中文字幕区| 亚洲色图欧美激情| 亚洲激情在线激情| 亚洲精品乱码久久久久久久久 | 亚洲高清免费一级二级三级| 亚洲欧洲国产日韩| 亚洲日本丝袜连裤袜办公室| **欧美大码日韩| 一区二区三区在线视频免费观看| 一区二区三区中文字幕精品精品| 亚洲欧美日韩中文播放| 国产精品成人免费在线| 亚洲人成小说网站色在线| 亚洲色图第一区| 亚洲二区在线观看| 日韩二区三区四区| 国产精品系列在线观看| 不卡在线视频中文字幕| 99久久精品国产导航| 在线精品视频小说1| 欧美精品成人一区二区三区四区| 欧美一级夜夜爽| 国产精品美女久久久久久久网站| 亚洲欧美在线高清| 午夜视频一区在线观看| 精品系列免费在线观看| 成人精品视频一区| 欧美日本一道本| 国产三级精品三级在线专区| 亚洲欧洲日本在线| 免费一级欧美片在线观看| 成人久久视频在线观看| 欧美综合欧美视频| 国产亚洲精品7777| 亚洲一级二级三级| 国产在线精品一区二区夜色| 99久久精品一区二区| 欧美一区午夜视频在线观看| 国产午夜亚洲精品不卡| 一区二区三区日韩精品视频| 国产一区二区三区免费播放| 色又黄又爽网站www久久| 91精品国产综合久久精品图片| 久久精品免费在线观看| 亚洲国产精品自拍| a美女胸又www黄视频久久| 日韩视频一区二区| 亚洲永久免费av| av激情综合网| 欧美日韩国产欧美日美国产精品| 国产在线国偷精品免费看| 国产精品亚洲视频|