/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 598 - (show annotations)
Fri Nov 28 18:29:59 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 2414 byte(s)
generate commit html, but we can't accept multiple commit_path values for now
1 package Frey::SVK;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6
7 has commit_path => (
8 documentation => 'path to commit',
9 is => 'rw',
10 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>) {
23 chomp;
24 $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;
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 {
51 my ($self) = @_;
52 {
53 modified => [ $self->modified ],
54 }
55 }
56
57 sub status_as_markup {
58 my ($self) = @_;
59 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 $self->add_css( qq| pre.l a { text-decoration: none; } | );
62 $status = qq|
63 <form>
64 <div style="background: #ffd; float: right; padding: 1em;">
65 <textarea name="message" width=20 height=4></textarea>
66 <br><input type="submit" value="Commit">
67 </div>
68 <pre class="l">$status</pre>
69 </form>
70 |;
71 $self->add_status( $status );
72 warn "status_as_markup ",length($status)," bytes";
73 return $status;
74 }
75
76 sub diff_as_markup {
77 my ($self) = @_;
78
79 my $diff = `svk diff`;
80
81 $diff = $self->html_escape( $diff );
82 $self->add_css( qq|
83 pre span.add { background: #dfd }
84 pre span.del { background: #fdd }
85 | );
86 $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;
87 $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;
88 $diff =~ s{^(===\s+)(\S+)$}{$1<a name="$2">$2</a>}gm;
89
90 $diff = qq|<pre>$diff</pre>|;
91 warn "diff_as_markup ",length($diff)," bytes";
92 return $diff;
93 }
94
95 sub as_markup {
96 my ($self) = @_;
97
98 if ( ! $self->can('html_escape') ) {
99 Frey::Web->meta->apply( $self );
100 $self->TODO( "Frey::Web role missing" );
101 }
102
103 my $html
104 = ( $self->status_as_markup || $self->error('no status_or_markup output') )
105 . ( $self->diff_as_markup || $self->error('no diff_as_markup output') )
106 ;
107 warn "as_markup ",length($html)," bytes";
108
109 return $html;
110 }
111
112 1;

  ViewVC Help
Powered by ViewVC 1.1.26