Acme-MUDLike

 view release on metacpan or  search on metacpan

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

      ($hex) = $item =~ m{^[a-z][a-z_:]+\((0x[0-9a-z]+)\)}i;
      $hex or ($hex) = $item =~ m{^0x([0-9a-z]+)}i;
      if($hex) {
          $ob = Devel::Pointer::deref(hex($hex));
      }
    };
    return $ob;
}

# actions

sub _call {
    my $self = shift;
    # XXX call a method an in object
    # XXX call sword name 
    my $item = shift;
    my $func = shift;
    my @args = @_; # XXX for each arg, go through the item finding code below, except keep identify if not found
    my $ob = $self->item_by_arg($item) or do {
        $self->tell_object("call: no item by that name/number/package name here");
        return;
    };
    for my $i (0..$#args) {
        my $x = $self->item_by_arg($args[$i]);
        $args[$i] = $x if $x;
    }
    $ob->can($func) or do {
        $self->tell_object("call:  item ``$item'' has no ``$func'' method");
        return;
    };
    $self->tell_object(join '', "Call: ", eval { $ob->can($func)->($ob, @args); } || "Error: ``$@''.");
    1;
}

sub _list {
    my $self = shift;
    my $i = 0;
    $self->tell_object(join '', 
        "Here, you see:\n", 
        map qq{$_\n}, 
        map { $i . ': ' . $_ }
        $self->environment->contents, $self->inventory->contents,
    ); 
}

sub _mark {
    my $self = shift;
    my $item = shift;
    my $ob = $self->item_by_arg($item) or do {
        $self->tell_object("mark: no item by that name/number/package name here");
        return;
    };
    $self->current_item = $ob;
}

sub _eval {
    my $self = shift;
    my $cmd = join ' ', @_;
    no warnings 'redefine';
    # *print = sub { $self->tell_object(@_); };  # this doesn't work reliablely due to possible context changes but worth a shot
    # *say = sub { $self->tell_object("@_\n"); }; # ack... doesn't work at all.
    select $self->request->{request}->{conn};  # would rather it went into their message buffer but comprimising for now
    my $res = eval($cmd) || "Error: ``$@''.";
    $self->tell_object("eval:\n$res");
}

sub _who {
    my $self = shift;
    $self->_look(@_); # for now
}

sub _look {
    my $self = shift;
    my @args = @_;
    # $self->tell_object(join '', "Here, you see:\n", map qq{$_\n}, map $_->name, $floor->contents); 
    $self->tell_object(join '', 
        "Here, you see:\n", 
        map qq{$_\n}, 
        map { $_->can('name') ? $_->name : ref($_) }
        $self->environment->contents
    ); 
}

sub _inv {
    my $self = shift;
    $self->_inventory(@_);
}

sub _i {
    my $self = shift;
    $self->_inventory(@_);
}

sub _inventory {
    my $self = shift;
    my @args = @_;
    $self->tell_object(join '', 
        "You are holding:\n", 
        map qq{$_\n}, 
        map { $_->can('name') ? $_->name : ''.$_ } 
        $self->inventory->contents
    ); 
}

sub _take {
    my $self = shift;
    my @args = @_;
    if(@args == 1) {
        # take thingie
        my $item = $floor->delete($args[0]) or do { $self->tell_object("No ``$args[0]'' here."); return; };
        $self->inventory->insert($item);
        $self->tell_object(qq{Taken.});
    } elsif(@args == 2) {
        $self->tell_object("I don't understand ``$args[0] $args[1]''.");
    } elsif(@args == 3) {
        if($args[1] ne 'from') {
            $self->tell_object("I don't understand ``$args[1] $args[2]''.");
            return;
        }
        my $container = $floor->named($args[2]) or do { $self->tell_object("No ``$args[2]'' here."); return; };
        my $item = $container->inventory->delete($args[0]) or do { $self->tell_object("No ``$args[0]'' here."); return; };

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

		return expr ? jQuery.filter(expr,this).r.length > 0 : false;
	},

	val: function( val ) {
		return val == undefined ?
			( this.length ? this[0].value : null ) :
			this.attr( "value", val );
	},

	html: function( val ) {
		return val == undefined ?
			( this.length ? this[0].innerHTML : null ) :
			this.empty().append( val );
	},
	domManip: function(args, table, dir, fn){
		var clone = this.length > 1; 
		var a = jQuery.clean(args);
		if ( dir < 0 )
			a.reverse();

		return this.each(function(){
			var obj = this;

			if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
				obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));

			jQuery.each( a, function(){
				fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
			});

		});
	}
};

jQuery.extend = jQuery.fn.extend = function() {
	// copy reference to target object
	var target = arguments[0],
		a = 1;

	// extend jQuery itself if only one argument is passed
	if ( arguments.length == 1 ) {
		target = this;
		a = 0;
	}
	var prop;
	while (prop = arguments[a++])
		// Extend the base object
		for ( var i in prop ) target[i] = prop[i];

	// Return the modified object
	return target;
};

jQuery.extend({
	noConflict: function() {
		if ( jQuery._$ )
			$ = jQuery._$;
		return jQuery;
	},

	// This may seem like some crazy code, but trust me when I say that this
	// is the only cross-browser way to do this. --John
	isFunction: function( fn ) {
		return !!fn && typeof fn != "string" && !fn.nodeName && 
			typeof fn[0] == "undefined" && /function/i.test( fn + "" );
	},
	
	// check if an element is in a XML document
	isXMLDoc: function(elem) {
		return elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
	},

	nodeName: function( elem, name ) {
		return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
	},
	// args is for internal usage only
	each: function( obj, fn, args ) {
		if ( obj.length == undefined )
			for ( var i in obj )
				fn.apply( obj[i], args || [i, obj[i]] );
		else
			for ( var i = 0, ol = obj.length; i < ol; i++ )
				if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
		return obj;
	},
	
	prop: function(elem, value, type, index, prop){
			// Handle executable functions
			if ( jQuery.isFunction( value ) )
				value = value.call( elem, [index] );
				
			// exclude the following css properties to add px
			var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;

			// Handle passing in a number to a CSS property
			return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
				value + "px" :
				value;
	},

	className: {
		// internal only, use addClass("class")
		add: function( elem, c ){
			jQuery.each( c.split(/\s+/), function(i, cur){
				if ( !jQuery.className.has( elem.className, cur ) )
					elem.className += ( elem.className ? " " : "" ) + cur;
			});
		},

		// internal only, use removeClass("class")
		remove: function( elem, c ){
			elem.className = c ?
				jQuery.grep( elem.className.split(/\s+/), function(cur){
					return !jQuery.className.has( c, cur );	
				}).join(" ") : "";
		},

		// internal only, use is(".class")
		has: function( t, c ) {
			t = t.className || t;
			// escape regex characters



( run in 2.490 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )