/[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 579 - (show annotations)
Fri Nov 28 01:16:21 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 1620 byte(s)
fix modified file extraction from svk
1 package Frey::SVK;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6
7 sub svk {
8 my ( $self, $exec, $coderef ) = @_;
9 open(my $svk, '-|', 'svk ' . $exec) or die "svk $exec: $@";
10 while(<$svk>) {
11 chomp;
12 $coderef->( $_ );
13 }
14 close($svk) or die "can't close svk $exec: $@";
15 }
16
17 sub modified {
18 my ($self) = @_;
19 my @modified;
20 my $svk = $self->svk('status -q', sub {
21 push @modified, $1 if /^\w+\s+(.+)/;
22 });
23 return @modified;
24 }
25
26 our $info; # cache, we use it on every hit
27 sub info {
28 my ($self) = @_;
29 return $info if $info;
30 my $svk = $self->svk('info', sub {
31 my ( $label, $value ) = split(/:\s+/, $_, 2);
32 $info->{$label} = $value if $label;
33 });
34 warn "# svk info ",$self->dump( $info );
35 return $info;
36 }
37
38 sub as_data {
39 my ($self) = @_;
40 {
41 modified => [ $self->modified ],
42 }
43 }
44
45 sub as_markup {
46 my ($self) = @_;
47
48 if ( ! $self->can('html_escape') ) {
49 Frey::Web->meta->apply( $self );
50 $self->TODO( "Frey::Web role missing" );
51 }
52
53 my $status = `svk status -q`;
54 $status =~ s{^(\w+\s+)(\S+)$}{$1<a href="#$2">$2</a>}gm;
55 $self->add_css( qq| pre.l a { text-decoration: none; } | );
56 $status = qq|<pre class="l">$status</pre>|;
57 $self->add_status( $status );
58
59 my $diff = `svk diff`;
60
61 $diff = $self->html_escape( $diff );
62 $self->add_css( qq|
63 pre span.add { background: #dfd }
64 pre span.del { background: #fdd }
65 | );
66 $diff =~ s{^(\+.+?)$}{<span class="add">$1</span>}gm;
67 $diff =~ s{^(\-.+?)$}{<span class="del">$1</span>}gm;
68 $diff =~ s{^(===\s+)(\S+)$}{$1<a name="$2">$2</a>}gm;
69
70 $diff = qq|<pre>$diff</pre>|;
71
72 my $html = $status . $diff;
73 warn "html ",length($html)," bytes";
74
75 return $html;
76 }
77
78 1;

  ViewVC Help
Powered by ViewVC 1.1.26