View Single Post
  #1  
Old 11-27-2012, 08:29 PM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default stupid perl tricks, vol. 1

i have a migraine, so i decided to share.

plugins\client_first.pl
Code:
use Scalar::Util qw(blessed);

# insert missing $client object as first parameter passed to subroutine
# usage: @_ = plugin::ClientFirst(@_);
sub ClientFirst
{
    unshift(@_, plugin::val('$client'))
        if ((blessed($_[0]) // '') ne 'Client');
    @_;
}
example usage (in plugins\check_hasitem.pl):
Code:
#checks to see if player has item
#useage plugin::check_hasitem($client, itemid);
sub check_hasitem
{
    @_ = plugin::ClientFirst(@_);
    my $client = shift;
    my $itmchk = shift;
    # yada yada
    ...;
}
with this addition, either of these would be valid:

Code:
my $found = plugin::check_hasitem($client, $itemid);
my $found = plugin::check_hasitem($itemid);
Reply With Quote