/usr/share/perl5/Prophet/Server/View.pm is in libprophet-perl 0.750-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | use strict;
use warnings;
package Prophet::Server::View;
use base 'Template::Declare';
use Template::Declare::Tags;
use URI::file;
# Prophet::Server::ViewHelpers overwrites the form {} function provided by
# Template::Declare::Tags. ViewHelpers uses Exporter::Lite which does not "use
# warnings". When prove -w or make test is run, $^W is set which turns on
# warnings in Exporter::Lite (most importantly, redefinition warnings). We
# don't want to warn about this specific redefinition, so we swap out
# $SIG{__WARN__} to shut up about it.
BEGIN {
no warnings 'redefine';
my $old_warn = $SIG{__WARN__} || sub { warn $_[0] };
local $SIG{__WARN__} = sub {
my $warning = shift;
$old_warn->($warning)
unless $warning =~ /Subroutine Prophet::Server::View::form redefined /;
};
require Prophet::Server::ViewHelpers;
Prophet::Server::ViewHelpers->import;
}
use Params::Validate;
use Prophet::Web::Menu;
our $APP_HANDLE;
sub app_handle {
my $self = shift;
$APP_HANDLE = shift if (@_);
return $APP_HANDLE;
}
our $CGI;
sub cgi {
my $self = shift;
$CGI = shift if (@_);
return $CGI;
}
our $MENU;
sub page_nav {
my $self = shift;
$MENU = shift if (@_);
return $MENU;
}
our $SERVER;
sub server {
my $self = shift;
$SERVER = shift if (@_);
return $SERVER;
}
template '_prophet_autocompleter' => sub {
my $self = shift;
my %args;
for (qw(q function record type class prop)) {
$args{$_} = $self->cgi->param($_);
}
my $obj = Prophet::Util->instantiate_record(
class => $self->cgi->param('class'),
uuid => $self->cgi->param('uuid'),
app_handle => $self->app_handle
);
my @possible;
if ( $obj) {
my $canon = { $args{prop} => $args{q} };
$obj->canonicalize_prop( $args{'prop'}, $canon, {} );
if ( $canon->{ $args{prop} } ne $args{q} ) {
push @possible, $canon->{ $args{'prop'} };
}
}
if ( $obj->loaded ) {
push @possible, $obj->prop( $args{'prop'} );
} else {
my $params = { $args{'prop'} => undef };
$obj->default_props($params);
push @possible, $params->{ $args{'prop'} };
# XXX fill in defaults;
}
push @possible, $obj->recommended_values_for_prop( $args{'prop'} );
my %seen;
for ( grep { defined && !$seen{$_}++ } @possible ) {
outs( $_ . "\n" ); #." | ".$_."\n");
}
};
sub default_page_title { 'Prophet' }
template head => sub {
my $self = shift;
my @args = shift;
head {
meta { attr { content => "text/html; charset=utf-8",
'http-equiv' => "Content-Type" }};
title { shift @args };
for ( $self->server->css ) {
link { { rel is 'stylesheet', href is link_to($_), type is "text/css", media is 'screen'} };
}
for ( $self->server->js ) {
script { { src is link_to($_), type is "text/javascript" } };
}
}
};
template footer => sub { };
template header => sub {
my $self = shift;
my $title = shift;
if ($self->page_nav) {
div { { class is 'page-nav'};
outs_raw($self->page_nav->render_as_menubar);
};
}
h1 { $title };
};
template '/' => page {
h1 { "This is a Prophet replica!" }
};
sub record_table {
my %args = validate(@_, {
records => 1,
url_prefix => { default => '' },
});
my $records = $args{records};
my $prefix = $args{url_prefix};
table {
my @items = $records ? $records->items : ();
if (@items) {
my @headers = $items[0]->_parse_format_summary;
row {
for (@headers) {
th { $_->{prop} }
}
}
}
for my $record (sort { $a->luid <=> $b->luid } @items) {
my $type = $record->type;
my $uuid = $record->uuid;
my @atoms = $record->format_summary;
row {
attr { id => "$type-$uuid", class => "$type" };
for my $i (0 .. $#atoms) {
my $atom = $atoms[$i];
my $prop = $atom->{prop};
cell {
attr {
class => "prop-$prop",
};
if ($i == 0) {
a {
attr {
href => link_to("$prefix$uuid.html"),
};
outs $atom->{value};
}
}
else {
outs $atom->{value};
}
}
}
}
}
}
}
template record_table =>
page {
my $self = shift;
my $records = shift;
record_table(records => $records);
};
template record => page {
my $self = shift;
my $record = shift;
p {
a {
attr {
href => link_to("index.html"),
};
outs "index";
}
}
hr {}
dl {
dt { 'UUID' }
dd { $record->uuid }
dt { 'LUID' }
dd { $record->luid };
my $props = $record->get_props;
for my $prop (sort keys %$props) {
dt { $prop }
dd { $props->{$prop} }
}
};
hr {}
h3 { "History" };
show record_changesets => $record;
# linked collections
for my $method ($record->collection_reference_methods) {
my $collection = $record->$method;
next if $collection->count == 0;
my $type = $collection->record_class->type;
hr {}
h3 { "Linked $type records" }
record_table(
records => $collection,
url_prefix => "../$type/",
);
}
};
private template record_changesets => sub {
my $self = shift;
my $record = shift;
my $uuid = $record->uuid;
ol {
for my $change ($record->changes) {
my @prop_changes = $change->prop_changes;
next if @prop_changes == 0;
if (@prop_changes == 1) {
li { $prop_changes[0]->summary };
next;
}
li {
ul {
for my $prop_change (@prop_changes) {
li {
outs $prop_change->summary;
}
}
}
}
}
}
};
sub generate_changeset_feed {
my $self = shift;
my %args = validate(@_, {
handle => 1,
title => 0,
});
my $handle = $args{handle};
my $title = $args{title} || 'Prophet replica ' . $handle->uuid;
require XML::Atom::SimpleFeed;
my $feed = XML::Atom::SimpleFeed->new(
id => "urn:uuid:" . $handle->uuid,
title => $title,
author => $self->app_handle->current_user_email,
);
my $newest = $handle->latest_sequence_no;
my $start = $newest - 20;
$start = 0 if $start < 0;
$handle->traverse_changesets(
after => $start,
callback => sub {
my %args = (@_);
$feed->add_entry(
title => 'Changeset ' . $args{changeset}->sequence_no,
# need uuid or absolute link :(
category => 'Changeset',
);
},
);
return $feed;
}
sub link_to ($) {
my $link = shift;
return URI::file->new($link)->rel("file://".$ENV{REQUEST_URI});
}
1;
|