/[Frey]/trunk/lib/Frey/SVK.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/SVK.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 498 by dpavlin, Mon Nov 24 21:31:54 2008 UTC revision 603 by dpavlin, Fri Nov 28 19:23:38 2008 UTC
# Line 1  Line 1 
1  package Frey::SVK;  package Frey::SVK;
2  use Moose;  use Moose;
3    
4  with 'Frey::Escape';  extends 'Frey';
5    with 'Frey::Web';
6    
7  sub modified {  has commit_path => (
8          my ($self) = @_;          documentation => 'path to commit',
9          my @modified;          is => 'rw',
10          open(my $svk, '-|', 'svk status -q') or die $@;          isa => 'ArrayRef|Str',
11    );
12    
13    has message => (
14            documentation => 'commit message',
15            is => 'rw',
16            isa => 'Str',
17    );
18    
19    sub svk {
20            my ( $self, $exec, $coderef ) = @_;
21            open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@";
22          while(<$svk>) {          while(<$svk>) {
23                  chomp;                  chomp;
24                  push @modified, $1 if /^M\s+(.+)/;                  $coderef->( $_ );
25          }          }
26            close($svk) or die "can't close svk $exec: $@";
27    }
28    
29    sub modified {
30            my ($self) = @_;
31            my @modified;
32            my $svk = $self->svk('status -q', sub {
33                    push @modified, $1 if /^\w+\s+(.+)/;
34            });
35          return @modified;          return @modified;
36  }  }
37    
38    our $info; # cache, we use it on every hit
39    sub info {
40            my ($self) = @_;
41            return $info if $info;
42            my $svk = $self->svk('info', sub {
43                    my ( $label, $value ) = split(/:\s+/, $_, 2);
44                    $info->{$label} = $value if $label;
45            });
46            warn "# svk info ",$self->dump( $info );
47            return $info;
48    }
49    
50  sub as_data {  sub as_data {
51          my ($self) = @_;          my ($self) = @_;
52          {          {
# Line 21  sub as_data { Line 54  sub as_data {
54          }          }
55  }  }
56    
57  sub as_markup {  sub status_as_markup {
58          my ($self) = @_;          my ($self) = @_;
   
59          my $status = `svk status -q`;          my $status = `svk status -q`;
60            $status =~ s{^(\w+\s+)(\S+)$}{$1<input name="commit_path" value="$2" type="checkbox"><a href="#$2">$2</a>}gm;
61            if ( $status ) {
62                    $self->add_css( qq| pre.l a { text-decoration: none; } | );
63                    $status = qq|
64                            <form>
65                            <div style="background: #ffd; float: right; padding: 1em;">
66                                    <textarea name="message" width=20 height=4></textarea>
67                                    <br><input type="submit" value="Commit">
68                            </div>
69                            <pre class="l">$status</pre>
70                            </form>
71                    |;
72                    $self->add_status( $status );
73            }
74            warn "status_as_markup ",length($status)," bytes";
75            return $status;
76    }
77    
78    sub diff_as_markup {
79            my ($self) = @_;
80    
81          my $diff   = `svk diff`;          my $diff   = `svk diff`;
82    
83          my $html          $diff = $self->html_escape( $diff );
84                  = qq|<pre>$status</pre><hr><pre>|          $self->add_css( qq|
85                  . $self->html_escape( $diff )          pre span.add { background: #dfd }
86                  . qq|</pre>|          pre span.del { background: #fdd }
87            | );
88            $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;
89            $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;
90            $diff =~ s{^(===\s+)(\S+)$}{$1<a name="$2">$2</a>}gm;
91    
92            $diff = qq|<pre>$diff</pre>|;
93            warn "diff_as_markup ",length($diff)," bytes";
94            return $diff;
95    }
96    
97    sub as_markup {
98            my ($self) = @_;
99    
100            if ( ! $self->can('html_escape') ) {
101                    Frey::Web->meta->apply( $self );
102                    $self->TODO( "Frey::Web role missing" );
103            }
104    
105            my $html
106                    = ( $self->status_as_markup || $self->error('no status_or_markup output') )
107                    . ( $self->diff_as_markup   || $self->error('no diff_as_markup output') )
108                  ;                  ;
109          warn "diff ",length($html)," bytes";          warn "as_markup ",length($html)," bytes";
110    
111          return $html;          return $html;
112  }  }

Legend:
Removed from v.498  
changed lines
  Added in v.603

  ViewVC Help
Powered by ViewVC 1.1.26