lib/TWiki/Contrib/MailerContrib/CompatibilityHacks.pm
changeset 0 414e01d06fd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/TWiki/Contrib/MailerContrib/CompatibilityHacks.pm	Sat Jan 26 15:50:53 2008 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +# Hack for older TWiki versions
     1.5 +package CompatibilityHacks;
     1.6 +
     1.7 +package IteratorHack;
     1.8 +
     1.9 +sub new {
    1.10 +    my ($class, $list) = @_;
    1.11 +    my $this = bless({list => $list, index => 0, next => undef }, $class);
    1.12 +    return $this;
    1.13 +}
    1.14 +
    1.15 +sub hasNext {
    1.16 +    my( $this ) = @_;
    1.17 +    return 1 if $this->{next};
    1.18 +    if( $this->{index} < scalar(@{$this->{list}}) ) {
    1.19 +        $this->{next} = $this->{list}->[$this->{index}++];
    1.20 +        return 1;
    1.21 +    }
    1.22 +    return 0;
    1.23 +}
    1.24 +
    1.25 +sub next {
    1.26 +    my $this = shift;
    1.27 +    $this->hasNext();
    1.28 +    my $n = $this->{next};
    1.29 +    $this->{next} = undef;
    1.30 +    return $n;
    1.31 +}
    1.32 +
    1.33 +package TWiki::Func;
    1.34 +
    1.35 +sub eachChangeSince {
    1.36 +    my ($web, $since) = @_;
    1.37 +
    1.38 +    my $changes;
    1.39 +    if( open(F, "<$TWiki::cfg{DataDir}/$web/.changes")) {
    1.40 +        local $/ = undef;
    1.41 +        $changes = <F>;
    1.42 +        close(F);
    1.43 +    }
    1.44 +
    1.45 +    $changes ||= '';
    1.46 +
    1.47 +    my @changes =
    1.48 +      map {
    1.49 +          # Create a hash for this line
    1.50 +          { topic => $_->[0], user => $_->[1], time => $_->[2],
    1.51 +              revision => $_->[3], more => $_->[4] };
    1.52 +      }
    1.53 +        grep {
    1.54 +            # Filter on time
    1.55 +            $_->[2] && $_->[2] >= $since
    1.56 +        }
    1.57 +          map {
    1.58 +              # Split line into an array
    1.59 +              my @row = split(/\t/, $_, 5);
    1.60 +              \@row;
    1.61 +          }
    1.62 +            reverse split( /[\r\n]+/, $changes);
    1.63 +
    1.64 +    return new IteratorHack( \@changes );
    1.65 +}
    1.66 +
    1.67 +1;