<package name="tinychat">
<domain name="papp" lang="en">

<!--
=head1 NAME

tinychar - a very tiny chat box for your server ;)

=head1 SYNOPSIS

 <import src="macro/tinychat"/>

 <:tinychat:>

 - OR -

 <:tinychat_top:>
 ....webpage....
 <:tinychat_bot:>

=cut

-->

<import pm="PApp::UserObs">username</import>

<macro name="_tinychat"><pxml><![CDATA[
<?sform tinychat_submit => 1:>
<:my $u = username || "ANON".getuid:>
#if delete $S{tinychat_submit} && $P{input} && !reload_p
<:
   lockenv {
      use POSIX ();
      my $r = getenv "PAPP_TINYCHAT";
      shift @$r while @$r > 5;
      push @$r, escape_html
                   sprintf "%s %s: %.60s",
                           POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime),
                           $u, $P{input};
      setenv "PAPP_TINYCHAT", $r;
   };
:>
#endif
<:
   my $r = getenv "PAPP_TINYCHAT";
   echo map "<tt>$_</tt><br />", @$r;
:>
<br />
<?$u:>: <?textfield { size => 70 }, "input":>
<?endform:>
]]></pxml></macro>

<macro name="tinychat*()"><pxml><![CDATA[
<small><:_tinychat:><br /></small>
]]></pxml></macro>

<macro name="tinychat_top*()"><pxml><![CDATA[
#if $S{papp_tinychat}
<p><small>
<?slink __"[move chatbox to bottom]", papp_tinychat => undef, SURL_SAVE_PREFS:>
<:_tinychat:>
</small></p>
#endif
]]></pxml></macro>

<macro name="tinychat_bot*()"><pxml><![CDATA[
#if !$S{papp_tinychat}
<p><small>
<:_tinychat:>
<?slink __"[move chatbox to top]", papp_tinychat => 1, SURL_SAVE_PREFS:>
</small></p>
#endif
]]></pxml></macro>

<perl><![CDATA[
=head1 SEE ALSO

L<PApp>

=head1 AUTHOR

 Marc Lehmann <pcg@goof.com>
 http://www.goof.com/pcg/marc/

=cut

]]></perl>

</domain>
</package>

