#
# GStage: a ridiculously (and intentionally) buggy IRC server
# lib/Class.pm: helper methods for dealing with Perl classes
#
# Copyright (c) 2010 Stephen Belcher (sycobuny)
#

package Class;

use warnings;
use strict;
use Method::Signatures;

method new($class:) {
    die "Can't instantiate a class!\n";
}

func in {
    my ($package) = caller;
    Class::exists($package) ? $package : undef;
}
*self = *in{CODE};

func exists($class) {
    no strict 'refs';
    scalar(%{$class . '::'});
}

func get($class) {
    my ($package) = ref($class) || $class;
    Class::exists($package) ? $package : undef;
}

1;

#
# GStage: a ridiculously (and intentionally) buggy IRC server
# lib/Class.pm: helper methods for dealing with Perl classes
#
# Copyright (c) 2010 Stephen Belcher (sycobuny)
#

package Class;

use warnings;
use strict;
use Method::Signatures;

method new($class:) {
    die "Can't instantiate a class!\n";
}

func in {
    my ($package) = caller;
    Class::exists($package) ? $package : undef;
}
*self = *in{CODE};

func exists($class) {
    no strict 'refs';
    defined(%{$class . '::'});
}

func get($class) {
    my ($package) = ref($class) || $class;
    Class::exists($package) ? $package : undef;
}

1;

Fix a bug with getting valid class names.
Fix a bug with getting valid class names.

Previously, if you called SomeFakeClass->new() inside of an eval{}
block, the execution wouldn't actually stop, and because the
%SomeFakeClass:: variable would have been magic'd into existence, the
call would register 'new' as being a valid key, and suddenly the class
would effectively be declared. In short, this means you could
accidentally create a class.

The new way can be circumvented by calling scalar(%SomeFakeClass::)
yourself, or simply saying %SomeFakeClass:: = (), but presumably if
you're doing that, you know what and why you're doing it, and it's
not just going to be something someone stumbles into.
