Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Web development II: Code

5 views
Skip to first unread message

Juerd

unread,
Sep 21, 2006, 6:41:30 AM9/21/06
to perl6...@perl.org
Some pseudo-code for illustration. Maybe we should put this on version
control or wiki, and collectively hack on it. If we can agree on any
certain route.

If anyone wants to go ahead and implement things, don't wait for me
please. I unfortunately do not have the tuits to do this in full. I
don't even have the tuits to write this up :)

class HTTP::Headers {
does Hash;

...
}

class HTTP::Message {
has HTTP::Headers $.headers handles <header> .= new;
has buf8 $.content is rw;
has HTTP::Message @.parts is rw;
has Str $.protocol is rw;

...
}

class HTTP::Argument {
does Array;
does Str;

# Possibly, does HTTP::Argument::Upload

...
}

class HTTP::Request {
is HTTP::Message;
does Hash; # %post{$key} // %get{$key}

has HTTP::Argument %.get;
has HTTP::Argument %.post; # lazy if .method eq 'POST' and
# .headers<Content-Length>
# > $arbitrary_yet_configurable
has Str %.cookies
has Str $.method where { $_ eq any <GET POST> };
has URI $.uri;

...
}

role HTTP::Argument::Upload {
...
}

class HTTP::Response {
is HTTP::Message;
has $.encoding = 'UTF-8' is rw;
...
}

class Web::Request {
is HTTP::Request;
}

class Web::Response {
is HTTP::Response;

has $.type where { $_ eq any <html xhtml wml raw> } is rw;
# sets Content-Type too, assumes UTF-8

# do something with .headers<Content-Type> to extract charset
# kill .content, because we're streaming
# add .print
}

role Web::Session {
has %.session;

...
}

role Web::Tags {
method tag_end () {
given $.response.type {
when 'html' { return '>' }
when 'xhtml' { return '/>' }
when 'wml' { return '/>' }
}
}

method img (...) {
return '<img ' ~ ... ~ .tag_end;
}
}

# Fill .request, .session
# Bind $*OUT and .response.print to whatever actually sends the data
role Web::Init::ModPerl {
submethod BUILD { ...; next METHOD or last METHOD }
}
role Web::Init::CGI {
submethod BUILD { ...; next METHOD or last METHOD }
}
role Web::Init::Foo {
submethod BUILD { ...; next METHOD or last METHOD }
}

class Web {
has Web::Request $.request handles ...;
has Web::Response $.response handles ...;

does Web::Init::ModPerl;
does Web::Init::CGI;
does Web::Init::Foo;


does Web::Util; # unless disabled?
# does Web::Session, if requested
# does Web::Tags, if requested

# exports automatically initalized object $web if requested
# with $response if requested, := $web.response
# ditto for $request, $session, $cookies

...
}

role Web::Util {
method entity ($foo) { ... }
method unentity ($foo) { ... }
method uriencode ($foo) { ... } # Not anything-dependent. Toss it?
method uridecode ($foo) { ... }

...
}

--
korajn salutojn,

juerd waalboer: perl hacker <ju...@juerd.nl> <http://juerd.nl/sig>
convolution: ict solutions and consultancy <sa...@convolution.nl>

Steffen Schwigon

unread,
Sep 21, 2006, 8:01:30 AM9/21/06
to perl6...@perl.org
Juerd <ju...@convolution.nl> writes:
> Some pseudo-code for illustration. Maybe we should put this on
> version control or wiki

Just to state this somewhere: if anyone needs a subversion repository
for such Perl6 related stuff, I'm willing to setup svn repositories
and users on our Dresden Perl Mongers server. Just ask me, now or in
future. Might be good, for instance, if the projects feel too early or
experimental to be hosted on major Perl/Pugs/Feather/Sourceforge
resources.

GreetinX
Steffen
--
Steffen Schwigon <http://renormalist.net>
Dresden Perl Mongers <http://dresden-pm.org/>

0 new messages