Skip to content

Commit

Permalink
Item11808: perltidy, v20120714 which has been installed on foswiki.or…
Browse files Browse the repository at this point in the history
…g enforces a few new rules. Developers, PLEASE UPGRADE! This commit should help

I've perltidy'ed everything which had a TIDY file.
Also fixed all errors shown by perltidy (maybe still one encoding issue for Confluence)
I've fixed everything I saw with obvious perl mistakes though. Doubt anybody
will care, as most were due to a bogus Build::Contrib::createnewextension which
Sven fixed recently.

git-svn-id: http://svn.foswiki.org/trunk/DBCacheContrib@15429 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed Sep 26, 2012
1 parent 7891f2d commit 8da4db3
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 230 deletions.
187 changes: 104 additions & 83 deletions lib/Foswiki/Contrib/DBCacheContrib.pm

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions lib/Foswiki/Contrib/DBCacheContrib/Archivist/BDB.pm
Expand Up @@ -25,33 +25,33 @@ package Foswiki::Contrib::DBCacheContrib::Archivist::BDB;
use strict;

use Foswiki::Contrib::DBCacheContrib::Archivist ();
our @ISA = ( 'Foswiki::Contrib::DBCacheContrib::Archivist' );
our @ISA = ('Foswiki::Contrib::DBCacheContrib::Archivist');

use Assert;

use BerkeleyDB ();

use Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Map ();
use Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Map ();
use Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Array ();

# Type constants
sub _SCALAR { 0 };
sub _MAP { 1 };
sub _ARRAY { 2 };
sub _SCALAR { 0 }
sub _MAP { 1 }
sub _ARRAY { 2 }

sub new {
my ( $class, $cacheName ) = @_;

my $workDir = Foswiki::Func::getWorkArea('DBCacheContrib');
my $workDir = Foswiki::Func::getWorkArea('DBCacheContrib');
$cacheName =~ s/\//\./go;
my $file = $workDir.'/'.$cacheName;
my $file = $workDir . '/' . $cacheName;

my $this = bless( {}, $class );
$this->{db} = new BerkeleyDB::Hash(
-Flags => BerkeleyDB::DB_CREATE(),
-Filename => $file
);
ASSERT(defined $this->{db}, "$file: $! $BerkeleyDB::Error") if DEBUG;
ASSERT( defined $this->{db}, "$file: $! $BerkeleyDB::Error" ) if DEBUG;
$this->{stubs} = {};
return $this;
}
Expand All @@ -61,46 +61,45 @@ sub new {

# Package private
sub db_get {
my ($this, $key) = @_;
my ( $this, $key ) = @_;
my $value;
my $status = $this->{db}->db_get($key, $value);
my $status = $this->{db}->db_get( $key, $value );
return $status ? undef : $value;
}

# Package private
sub db_set {
my ($this, $key, $value) = @_;
my $status = $this->{db}->db_put($key, $value);
my ( $this, $key, $value ) = @_;
my $status = $this->{db}->db_put( $key, $value );
return $status;
}

# Package private
sub db_exists {
my ($this, $key) = @_;
my ( $this, $key ) = @_;
my $value;
my $status = $this->{db}->db_get($key, $value);
my $status = $this->{db}->db_get( $key, $value );
return $status ? 0 : 1;
}

# Package private
sub db_delete {
my ($this, $key) = @_;
my ( $this, $key ) = @_;
my $status = $this->{db}->db_del($key);
return $status;
}


sub getRoot {
my $this = shift;
unless ( $this->{root} ) {
my $root = $this->db_get('__ROOT__');
if ( $root ) {
$this->{root} = $this->decode( $root );
if ($root) {
$this->{root} = $this->decode($root);
}
else {
# The root is always a map
$this->{root} = $this->newMap();
$this->{db}->db_put('__ROOT__', $this->encode($this->{root}))
$this->{db}->db_put( '__ROOT__', $this->encode( $this->{root} ) );
}
}
return $this->{root};
Expand Down Expand Up @@ -165,6 +164,7 @@ sub encode {
$value = $value->{id};
}
elsif ( ref($value) ) {

# SMELL: could use Data::Dumper or another freezer
die 'Unstorable type ' . ref($value);
}
Expand All @@ -191,7 +191,7 @@ sub decode {
$this->{stubs}->{$value} ||= $this->newArray( id => $value );
}
else {
die 'Corrupt DB; type '.$type;
die 'Corrupt DB; type ' . $type;
}
$value = $this->{stubs}->{$value};
}
Expand All @@ -206,12 +206,12 @@ sub allocateID {
my $oid = $this->db_get('__ID__') || 0;
if ( defined $id ) {
if ( $id >= $oid ) {
$this->db_set('__ID__', $id + 1);
$this->db_set( '__ID__', $id + 1 );
}
return $id;
}
else {
$this->db_set('__ID__', $oid + 1);
$this->db_set( '__ID__', $oid + 1 );
return $oid;
}
}
Expand Down
19 changes: 11 additions & 8 deletions lib/Foswiki/Contrib/DBCacheContrib/Archivist/BDB/Array.pm
Expand Up @@ -4,10 +4,13 @@ package Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Array;
use strict;

use Foswiki::Contrib::DBCacheContrib::Array ();

# Mixin collections code
use Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Collection ();
our @ISA = ( 'Foswiki::Contrib::DBCacheContrib::Array',
'Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Collection' );
our @ISA = (
'Foswiki::Contrib::DBCacheContrib::Array',
'Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Collection'
);

use Assert;

Expand All @@ -33,14 +36,14 @@ sub STORE {
if ( $index >= $this->FETCHSIZE() ) {
$this->STORESIZE( $index + 1 );
}
$this->{archivist}->db_set(
$this->getID($index), $this->{archivist}->encode($value));
$this->{archivist}
->db_set( $this->getID($index), $this->{archivist}->encode($value) );
}

sub FETCHSIZE {
my ($this) = @_;
unless (defined $this->{size}) {
$this->{size} = $this->{archivist}->db_get('S'.$this->{id}) || 0;
unless ( defined $this->{size} ) {
$this->{size} = $this->{archivist}->db_get( 'S' . $this->{id} ) || 0;
}
return $this->{size};
}
Expand All @@ -50,7 +53,7 @@ sub STORESIZE {
my $sz = $this->FETCHSIZE();
if ( $count > $sz ) {
for ( my $i = $sz ; $i < $count ; $i++ ) {
$this->{archivist}->db_set( $this->getID($i), '');
$this->{archivist}->db_set( $this->getID($i), '' );
}
}
elsif ( $count < $sz ) {
Expand All @@ -59,7 +62,7 @@ sub STORESIZE {
}
}
$this->{size} = $count;
$this->{archivist}->db_set( 'S'.$this->{id}, $count );
$this->{archivist}->db_set( 'S' . $this->{id}, $count );
}

sub EXISTS {
Expand Down
Expand Up @@ -7,13 +7,13 @@ use Assert;
sub getID {
my ( $this, $k ) = @_;
return $this->{id} unless defined $k;
return $this->{id}."\0$k";
return $this->{id} . "\0$k";
}

sub FETCH {
my ( $this, $key ) = @_;
return $this->{archivist}->decode(
$this->{archivist}->db_get( $this->getID($key) ));
return $this->{archivist}
->decode( $this->{archivist}->db_get( $this->getID($key) ) );
}

sub DESTROY {
Expand Down
34 changes: 19 additions & 15 deletions lib/Foswiki/Contrib/DBCacheContrib/Archivist/BDB/Map.pm
Expand Up @@ -11,10 +11,13 @@ package Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Map;
use strict;

use Foswiki::Contrib::DBCacheContrib::Map ();

# Mixin collections code
use Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Collection ();
our @ISA = ( 'Foswiki::Contrib::DBCacheContrib::Map',
'Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Collection' );
our @ISA = (
'Foswiki::Contrib::DBCacheContrib::Map',
'Foswiki::Contrib::DBCacheContrib::Archivist::BDB::Collection'
);

use Assert;

Expand All @@ -23,7 +26,7 @@ sub new {
my $class = shift;
my %args = @_;
my $initial;
if ( $args{initial}) {
if ( $args{initial} ) {

# Delay parsing until we are bound
$initial = $args{initial};
Expand All @@ -41,11 +44,12 @@ sub new {
$this->{id} = $this->{archivist}->allocateID();
}
if ($initial) {
if (ref($initial)) {
while (my ($k, $v) = each %$initial) {
$this->STORE($k, $v);
if ( ref($initial) ) {
while ( my ( $k, $v ) = each %$initial ) {
$this->STORE( $k, $v );
}
} else {
}
else {
$this->parse($initial);
}
}
Expand All @@ -58,23 +62,23 @@ sub STORE {
my %keys = map { $_ => 1 } $this->getKeys();
unless ( $keys{$key} ) {
push( @{ $this->{keys} }, $key );
$this->{archivist}->db_set(
'K'.$this->{id}, join( "\0", @{ $this->{keys} } ));
$this->{archivist}
->db_set( 'K' . $this->{id}, join( "\0", @{ $this->{keys} } ) );
}
$this->{archivist}->db_set($id, $this->{archivist}->encode($value));
$this->{archivist}->db_set( $id, $this->{archivist}->encode($value) );
}

sub FIRSTKEY {
my $this = shift;
$this->getKeys();
$this->{keyIt} = 0;
return $this->{keys}->[$this->{keyIt}++];
return $this->{keys}->[ $this->{keyIt}++ ];
}

sub NEXTKEY {
my ( $this, $lastkey ) = @_;
return unless $this->{keyIt} < scalar(@{$this->{keys}});
return $this->{keys}->[$this->{keyIt}++];
return unless $this->{keyIt} < scalar( @{ $this->{keys} } );
return $this->{keys}->[ $this->{keyIt}++ ];
}

sub EXISTS {
Expand All @@ -88,7 +92,7 @@ sub DELETE {
$this->getKeys();
my %keys = map { $_ => 1 } $this->getKeys();
delete( $keys{$key} );
$this->{archivist}->db_set('K'.$this->{id}, join( "\0", keys %keys ));
$this->{archivist}->db_set( 'K' . $this->{id}, join( "\0", keys %keys ) );
$this->{keys} = undef;
}

Expand All @@ -109,7 +113,7 @@ sub getKeys {

unless ( defined $this->{keys} ) {
@{ $this->{keys} } =
split( "\0", $this->{archivist}->db_get('K'.$this->{id}) || '' );
split( "\0", $this->{archivist}->db_get( 'K' . $this->{id} ) || '' );
}

return @{ $this->{keys} };
Expand Down
6 changes: 3 additions & 3 deletions lib/Foswiki/Contrib/DBCacheContrib/Archivist/Storable.pm
Expand Up @@ -5,7 +5,7 @@ package Foswiki::Contrib::DBCacheContrib::Archivist::Storable;
use strict;

use Foswiki::Contrib::DBCacheContrib::MemArchivist ();
our @ISA = ( 'Foswiki::Contrib::DBCacheContrib::MemArchivist' );
our @ISA = ('Foswiki::Contrib::DBCacheContrib::MemArchivist');

use Storable;

Expand All @@ -23,8 +23,8 @@ sub DESTROY {
sub sync {
my $this = shift;

#my ($package, $filename, $line) = caller(2);
#print STDERR "called sync $this->{_file} from $package, $line\n";
#my ($package, $filename, $line) = caller(2);
#print STDERR "called sync $this->{_file} from $package, $line\n";

# Clear the archivist to avoid having pointers in the Storable
$this->{root}->setArchivist(undef) if $this->{root};
Expand Down
8 changes: 5 additions & 3 deletions lib/Foswiki/Contrib/DBCacheContrib/Array.pm
Expand Up @@ -29,10 +29,11 @@ package Foswiki::Contrib::DBCacheContrib::Array;
use strict;

use Tie::Array ();

# Mixin archivability
use Foswiki::Contrib::DBCacheContrib::Archivable ();

our @ISA = ('Tie::Array', 'Foswiki::Contrib::DBCacheContrib::Archivable');
our @ISA = ( 'Tie::Array', 'Foswiki::Contrib::DBCacheContrib::Archivable' );

use Assert;

Expand Down Expand Up @@ -271,8 +272,9 @@ sub sum {
die "$field has no subfield $subfields"
unless ( ref($fieldval) );
$sum += $fieldval->sum($subfields);
} elsif ( $fieldval =~
m/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ ) {
}
elsif ( $fieldval =~ m/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ )
{
$sum += $fieldval;
}
}
Expand Down
14 changes: 8 additions & 6 deletions lib/Foswiki/Contrib/DBCacheContrib/Map.pm
Expand Up @@ -44,6 +44,7 @@ package Foswiki::Contrib::DBCacheContrib::Map;
use strict;

use Tie::Hash ();

# Mixin archivability
use Foswiki::Contrib::DBCacheContrib::Archivable;

Expand All @@ -60,14 +61,15 @@ use Assert;

sub new {
my $class = shift;
my %args = @_;
my $this = bless( {}, $class );
my %args = @_;
my $this = bless( {}, $class );
if ( $args{initial} ) {
if (ref($args{initial}) eq 'HASH') {
while (my ($k, $v) = each %{$args{initial}}) {
$this->STORE($k, $v);
if ( ref( $args{initial} ) eq 'HASH' ) {
while ( my ( $k, $v ) = each %{ $args{initial} } ) {
$this->STORE( $k, $v );
}
} else {
}
else {
$this->parse( $args{initial} );
}
}
Expand Down

0 comments on commit 8da4db3

Please sign in to comment.