Created
May 8, 2012 03:41
-
-
Save xenoterracide/2632369 to your computer and use it in GitHub Desktop.
class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyClass { | |
| method foo { return $self->{foo} } | |
| method info { return load_class('Class::Info')->new } | |
| } | |
| MyClass->new->foo; | |
| # to be the equivalent of | |
| { | |
| use strict; | |
| use warnings; | |
| use utf8; # so our class can be named with utf8 | |
| package MyClass { | |
| use namespace::autoclean; | |
| use Scalar::Util qw( blessed ); | |
| # use Class::Load qw( load_class ); | |
| # or similar for a feature that I'm hoping will be in Class::Load in the future | |
| # for now I'll show with require | |
| sub new { # or something better, point is that there's a default simple constructor | |
| my $class = shift; | |
| my $self = ref $_[0] eq 'HASH' ? $_[0] : { @_ }; | |
| bless $self, $class; | |
| return $self; | |
| } | |
| sub foo { my $self = shift; return $self->{foo} } | |
| sub info { #doesn't actually do what I'm really suggesting | |
| my $self = shift; | |
| require Class::Info; | |
| return Class::Info->new; | |
| } | |
| } | |
| } | |
| MyClass->new->foo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment