/[Frey]/trunk/lib/Frey/VCI.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/VCI.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 513 - (show annotations)
Tue Nov 25 13:53:53 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1899 byte(s)
rewrite SourceSnoop into Frey::VCI as_markup
1 package Frey::VCI;
2
3 use Moose;
4
5 use lib '/rest/cvs/vci/lib'; # FIXME
6 use VCI;
7
8 use HTML::Entities qw/encode_entities/;
9
10 extends 'Frey';
11 with 'Frey::Web';
12
13 use Data::Dump qw/dump/;
14
15 has 'repo' => (
16 is => 'rw',
17 isa => 'Str',
18 required => 1,
19 default => 'file:///home/dpavlin/private/svn/Frey',
20 );
21
22 has 'type' => (
23 is => 'rw',
24 isa => 'Str',
25 required => 1,
26 default => 'Svn',
27 );
28
29 has 'project' => (
30 is => 'rw',
31 isa => 'Str',
32 required => 1,
33 default => 'trunk',
34 );
35
36 has 'revision' => (
37 is => 'rw',
38 isa => 'Int|Str',
39 documentation => 'last revision in repository if not specified',
40 );
41
42 sub pre_dump {
43 my $o = shift;
44 # because Data::Dumper::HTML sucks
45 my $t;
46 if ( blessed($o) && $o->can('dump') ) {
47 $t = $o->dump;
48 $t =~ s/ {8}/ /gm;
49 } else {
50 $t = dump( $o );
51 }
52 return '<hr><pre>' . encode_entities($t) . '</pre><hr>';
53 }
54
55 sub as_markup {
56 my ( $self ) = @_;
57
58 my $html;
59
60 my $repo = VCI->connect(
61 repo => $self->repo,
62 type => $self->type,
63 debug => $self->debug,
64 );
65
66 my @projects_available = map { $_->name } @{ $repo->projects };
67 die $self->project," not one of valid projects ", dump( @projects_available ) unless grep { $self->project } @projects_available;
68
69 my $project = $repo->get_project( name => $self->project );
70 my $rev = $self->revision || $project->head_revision;
71
72 my $commit = $project->get_commit( revision => $rev ) || die "can't get revision $rev: $@";
73
74 sub div {
75 my ( $class, $text ) = @_;
76 return "<div class=\"$class\">$text</div>";
77 }
78
79 my $diff = $commit->as_diff;
80
81 my $body =
82 '<h1>Commit</h1>' .
83 div( 'revision', $commit->revision ) .
84 div( 'commiter', $commit->committer ) .
85 div( 'date', $commit->time->iso8601 ) .
86 div( 'message', $commit->message ) .
87 '<pre>' . encode_entities( $diff->raw ) . '</pre>' .
88 pre_dump( $diff );
89
90 $self->title( $self->repo . '/' . $project->name );
91 return $body;
92 };
93
94 warn "## VCI loaded";
95
96 1;

  ViewVC Help
Powered by ViewVC 1.1.26