lib/TWiki/Contrib/MailerContrib/CompatibilityHacks.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
permissions -rw-r--r--
RELEASE 4.2.0 freetown
colas@0
     1
# Hack for older TWiki versions
colas@0
     2
package CompatibilityHacks;
colas@0
     3
colas@0
     4
package IteratorHack;
colas@0
     5
colas@0
     6
sub new {
colas@0
     7
    my ($class, $list) = @_;
colas@0
     8
    my $this = bless({list => $list, index => 0, next => undef }, $class);
colas@0
     9
    return $this;
colas@0
    10
}
colas@0
    11
colas@0
    12
sub hasNext {
colas@0
    13
    my( $this ) = @_;
colas@0
    14
    return 1 if $this->{next};
colas@0
    15
    if( $this->{index} < scalar(@{$this->{list}}) ) {
colas@0
    16
        $this->{next} = $this->{list}->[$this->{index}++];
colas@0
    17
        return 1;
colas@0
    18
    }
colas@0
    19
    return 0;
colas@0
    20
}
colas@0
    21
colas@0
    22
sub next {
colas@0
    23
    my $this = shift;
colas@0
    24
    $this->hasNext();
colas@0
    25
    my $n = $this->{next};
colas@0
    26
    $this->{next} = undef;
colas@0
    27
    return $n;
colas@0
    28
}
colas@0
    29
colas@0
    30
package TWiki::Func;
colas@0
    31
colas@0
    32
sub eachChangeSince {
colas@0
    33
    my ($web, $since) = @_;
colas@0
    34
colas@0
    35
    my $changes;
colas@0
    36
    if( open(F, "<$TWiki::cfg{DataDir}/$web/.changes")) {
colas@0
    37
        local $/ = undef;
colas@0
    38
        $changes = <F>;
colas@0
    39
        close(F);
colas@0
    40
    }
colas@0
    41
colas@0
    42
    $changes ||= '';
colas@0
    43
colas@0
    44
    my @changes =
colas@0
    45
      map {
colas@0
    46
          # Create a hash for this line
colas@0
    47
          { topic => $_->[0], user => $_->[1], time => $_->[2],
colas@0
    48
              revision => $_->[3], more => $_->[4] };
colas@0
    49
      }
colas@0
    50
        grep {
colas@0
    51
            # Filter on time
colas@0
    52
            $_->[2] && $_->[2] >= $since
colas@0
    53
        }
colas@0
    54
          map {
colas@0
    55
              # Split line into an array
colas@0
    56
              my @row = split(/\t/, $_, 5);
colas@0
    57
              \@row;
colas@0
    58
          }
colas@0
    59
            reverse split( /[\r\n]+/, $changes);
colas@0
    60
colas@0
    61
    return new IteratorHack( \@changes );
colas@0
    62
}
colas@0
    63
colas@0
    64
1;