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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 142 - (show annotations)
Wed Jul 16 14:14:18 2008 UTC (14 years, 4 months ago) by dpavlin
File size: 1612 byte(s)
skeleton of reload functionality, non-working for now
1 package Frey::Web;
2 use Moose::Role;
3 use MooseX::AttributeHelpers;
4
5 use Continuity::Widget::DomNode;
6 use Data::Dump qw/dump/;
7 use Carp qw/confess/;
8
9 has 'javascript' => (
10 metaclass => 'Collection::Array',
11 is => 'rw',
12 isa => 'ArrayRef[Str]',
13 default => sub { [] },
14 provides => {
15 'push' => 'add_javascript',
16 },
17 );
18
19 has 'css' => (
20 metaclass => 'Collection::Array',
21 is => 'rw',
22 isa => 'ArrayRef[Str]',
23 default => sub { [ 'static/app.css' ] },
24 provides => {
25 'push' => 'add_css',
26 },
27 );
28
29 sub dom2html {
30 # warn "## dom2html ",dump( @_ );
31 return Continuity::Widget::DomNode->create( @_ )->to_string;
32 }
33
34 sub _unroll_markup {
35 # warn "## _unroll_markup ",dump( @_ );
36 my ( $markup, $array ) = @_;
37 my $out = '';
38 foreach my $path ( @$array ) {
39 $path =~ s!^/!!;
40 confess "can't find $path" unless -e $path;
41 $out .= sprintf( $markup, $path );
42 }
43 return $out;
44 }
45
46 our $reload_counter = 0;
47
48 sub page {
49 my $self = shift;
50 my $a = {@_};
51
52 $reload_counter++;
53
54 my $html = qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|
55 . _unroll_markup( qq|<script type="text/javascript" src="/%s"></script>|, $self->javascript )
56 . _unroll_markup( qq|<link type="text/css" rel="stylesheet" href="/%s" media="screen">|, $self->css )
57 . '<title>' . ( $a->{title} || ref($self) ) . '</title>'
58 . ( $a->{head} || '' )
59 . '</head><body>'
60 . ( $a->{body} || '<!-- no body -->' )
61 . qq|<div class="status-line"> <a href="/">Frey</a> $Frey::VERSION <a href="?reload=$reload_counter">reload</a> </div>|
62 . '</body></html>'
63 ;
64
65 warn "## >>> page ",length($html), " bytes\n" if $self->debug;
66
67 return $html;
68 }
69
70 1;

  ViewVC Help
Powered by ViewVC 1.1.26