github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jettero / object--previous

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (3)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (3)
    • 1.1011
    • 1.1010
    • 1.1007
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Object::Previous lets me do something I always wished perl could do -- I used to do it in LPC all the time, missed it. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

worst bug ever, arrgh, I thought I found the last of these years ago 
jettero (author)
Wed Jul 08 10:11:05 -0700 2009
commit  78ef217f31e3004a34f9142037fbc7772a3faef0
tree    407e3b37a1f3c78f625058190c8b24b35d17aa69
parent  20f9ea4268533754705c290b9e4cd5567dd2b45c
object--previous /
name age
history
message
file .perlcriticrc Loading commit data...
file Changes
file MANIFEST
file MANIFEST.SKIP
file Makefile.PL
file Previous.pm
file Previous.pod
file Previous.xs
file README
file pp_caller.txt
directory t/
README
NAME
    Object::Previous - find the instance of the object that called your
    function

SYNOPSIS
        package Human;
        use Object::Previous;

        sub new { bless {hit_points=>(7+int rand 6)} }
        sub hurt_us {
            my $body = shift;
               $body->{hit_points} -= shift;

            if( (int rand 10) == 0 ) {
                # every once in a while, damaging bodies hurts the sword:

                my $sword = previous_object();
                   $sword->hurt_us(1+int rand 4);
            }
        }

        package Sword;
        sub new { bless {hit_points=>2} }
        sub hurt_human {
            my $sword = shift;
            my $target = shift;

            $target->hurt_us( 1+int rand 8 );
        }
        sub hurt_us {
            my $sword = shift;
               $sword->{hit_points} -= shift;

            if( $sword->{hit_points} <= 0 ) {
                warn "the attacker's sword broke!";
            }
        }

previous_object()
    previous_object() either returns the blessed ref of the caller or undef
    if it is not possible to find it.

CAVEATS
    If you tinker with the @_ in the caller object, previous_object() won't
    work. Curiously, certain ways of tinkinkering don't hurt and others do.

        my $self = shift; # doesn't hurt previous_object()
        shift while @_;   # doesn't hurt previous_object()
        splice @_, 0, 30; # doesn't hurt previous_object()

        unshift @_, "borked"; # breaks previous_object();
        @_ = ();              # breaks previous_object();

AUTHOR(S)
    Most of the code was ripped from Perl and from perlmonks.org, but it was
    glued together by me.

    Paul Miller <paul@cpan.org>

    I am using this software in my own projects... If you find bugs, please
    please please let me know. :) Actually, let me know if you find it handy
    at all. Half the fun of releasing this stuff is knowing that people use
    it.

COPYRIGHT
    Copyright (c) 2007 Paul Miller

    Licensed under the same terms as Perl itself.

SEE ALSO
    perl(1), Devel::Stacktrace, perlmonks.org, cop.h, pp_ctl.c

NAME
    Object::Previous - find the instance of the object that called your
    function

SYNOPSIS
        package Human;
        use Object::Previous;

        sub new { bless {hit_points=>(7+int rand 6)} }
        sub hurt_us {
            my $body = shift;
               $body->{hit_points} -= shift;

            if( (int rand 10) == 0 ) {
                # every once in a while, damaging bodies hurts the sword:

                my $sword = previous_object();
                   $sword->hurt_us(1+int rand 4);
            }
        }

        package Sword;
        sub new { bless {hit_points=>2} }
        sub hurt_human {
            my $sword = shift;
            my $target = shift;

            $target->hurt_us( 1+int rand 8 );
        }
        sub hurt_us {
            my $sword = shift;
               $sword->{hit_points} -= shift;

            if( $sword->{hit_points} <= 0 ) {
                warn "the attacker's sword broke!";
            }
        }

previous_object
    "previous_object" either returns the blessed ref of the caller or
    "undef" if it is not possible to find it.

CAVEATS
    If you tinker with the @_ in the caller object, "previous_object" won't
    work. Curiously, certain ways of tinkering don't hurt and others do.

        my $self = shift; # doesn't hurt previous_object()
        shift while @_;   # doesn't hurt previous_object()
        splice @_, 0, 30; # doesn't hurt previous_object()

        unshift @_, "borked"; # breaks previous_object();
        @_ = ();              # breaks previous_object();

    Another caveat is that almost everyone things this is a really bad idea
    and/or bad practice.

    The only place I've ever seen it actually used in practice is for
    security in MudOS (LPC, not perl). LPC has a native previous_object
    function. It's used to make sure calling objects are really admin-shells
    or really the mob they're supposed to be -- anywhere you wouldn't want
    someone to just be able to pass in an appropriate object to subvert the
    security.

AUTHOR(S)
    Most of the code was ripped from Perl and from perlmonks, but it was
    glued together by me.

    Paul Miller "<paul@cpan.org>"

    I am using this software in my own projects... If you find bugs, please
    please please let me know. :) Actually, let me know if you find it handy
    at all. Half the fun of releasing this stuff is knowing that people use
    it.

COPYRIGHT
    Copyright (c) 2007-2009 Paul Miller

    Licensed under the same terms as Perl itself.

SEE ALSO
    perl(1), Devel::Stacktrace, perlmonks node 690713, perlmonks node
    690795, cop.h, pp_ctl.c

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server