Acme-MUDLike

 view release on metacpan or  search on metacpan

lib/Acme/MUDLike.pm  view on Meta::CPAN

package Acme::MUDLike;

use 5.008000;
use strict;
use warnings;

use Continuity;
use Carp;
use Devel::Pointer;

our $VERSION = '0.04';

# Todo:
# 
# *  what would be *really* cool is doing on the fly image generation to draw an overhead map of the program based on a 
#    graph of which objects reference which other objects and let people go walk around inside of their program
#    and then they could fight methods and use global variables as weapons!
#
# * http://zvtm.sourceforge.net/zgrviewer.html or something similar for showing the user the "map" of
#   nodes/rooms/whatever made of has-a references or something.
# 
# * /goto should put you inside an arbitrary object, /look should list as exits and/or items the object references contained by that object
#   in other words, break away from our rigid API for inventory/room/etc.
# 
# * need a black list black list, so we can re-add ourself to things that get serialized by Acme::State even though we're in %INC
# 
# * need an error log viewabe by all.
# 
# * eval and its output should be sent to the whole room.
# 
# * Better account management.
# 
# * There's code around to parse LPC and convert it to Perl.  It would be neat to offer a full blown 2.4.5
#   lib for people to play around in.
# 
# * Acme::IRCLike would probably be more popular -- bolt an IRC server onto your app.
# 
# * Also, a telnet interface beyond just an HTTP interface would be nice.  Should be easy to do.
# 
# * Let "players" wander between apps.  Offer RPC to support this.
# 
# * Optionally take an existing Continuity instance with path_session set and optionally parameters
#   for the paths to use for chat pull and commands.
#   Not sure how to work this; each path gets its own coroutine, but there is still only one main().
#   Continuity doesn't have a registry of which paths go to which callbacks.
# 
# Done:
# 
# * mark/call commands should have a current object register, so you can do /call thingie whatever /next and then be calling 
#   into the object returned by thingie->whatever
# 
# * /list (like look, but with stringified object references)
# 
# * /mark <n>  ... or... /mark <stringified obj ref>
# 
# * messages still in duplicate when the same player logs in twice; make room's tell_object operate uniquely.
# 
# * messages in triplicate because each player has three routines and is inserted into the floor three times.  oops.
# 
# * build the ajax.chat.js into source. -- okay, test.
# 
# * eval, call
# 
# * inventory's insert() method should set the insertee's environment to itself.  that way, all objects have an environment.
# 
# * Commands need to do $floor->tell_object or $self->tell_object rather than output directly.
# 
# * Put @messages into the room ($floor).  Get the chat action out of the main loop.  Dispatch all
#   actions.  Maybe.
# 

our $password; # Acme::State friendly
our $floor;    # holds all other objects
our $players;  # holds all players; kind of like $floor except in the future, inactive players might get removed from the floor, or there might be multiple rooms

my $continuity;
my $got_message;   # diddled to wake the chat event watchers

$SIG{PIPE} = 'IGNORE';

sub new {
    my $package = shift;
    my %args = @_;

    die "We've already got one" if $continuity;

    $password = delete $args{password} if exists $args{password};
    $password ||= join('', map { $_->[int rand scalar @$_] } (['a'..'z', 'A'..'Z', '0'..'9']) x 8),

    my $staticp = sub { 
        # warn "staticp: url->path: ``@{[ $_[0]->url->path ]}''"; 
        return 0 if $_[0]->url->path =~  m/\.js$/; 
        # warn "staticp: dynamic js handling override not engaged";
        return $_[0]->url->path =~ m/\.(jpg|jpeg|gif|png|css|ico|js)$/ 
    };

    $continuity = $args{continuity} || Continuity->new(
        staticp => sub { $staticp->(@_); },
        callback => sub { login(@_) },
        path_session => 1,
        port => 2000,
        %args,
    );



( run in 2.411 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )