Coder Social home page Coder Social logo

pudu's Introduction

[[meta author="Delon Newman [email protected]"]]

NAME

Pudu - A light-weight Moose-like object system that makes it easy to create encapsulated, immutable objects

SYNOPSIS

package Animal {
    use Pudu;

    has name => ( is => 'rw' );

    method speak => sub {
        "grunt"
    };

    private {
        method hide => sub {
            "this is my hiding place"
        };
    };

    protected {
        method share => sub {
            "I share with my friends"
        };
    };
}

package Cat {
    use Pudu;
    is 'Animal';

    method speak => sub {
        "meow"
    };

    method reveal => sub {
        self->share . " and strangers";
    };

    method betray => sub {
        self->hide
    };
}

$a = Animal->new(name => 'Bruce');
$a->speak # => "grunt"
$a->hide  # dies
$a->share # dies

$c = Cat->new(name => 'Selina');
$c->speak  # => "meow"
$c->reveal # => "I share with my friends and strangers"
$c->betray # dies

FUNCTIONS

UTILITIES

  • clean

Removes all keywords from from the given namespace. It's used internally by Pudu::Object.

Example:

package Cat {
    use Pudu;

    has name => ( is => 'rw' );

    method speak => sub {
        "meow"
    };
}

my $c = Cat->new(name => "Selina");
$c->name;   # => "Selina"
$c->speak;  # => "meow"
$c->has;    # dies
$c->method; # dies

KEYWORDS

The following functions are all exported by default when using the Pudu module, and are designed to provide some syntactic sugar for the inner workings.

  • has

Keyword for defining attributes

Example:

package Point {
    use Pudu;

    has x => ( is => 'rw' );
    has y => ( is => 'rw' );
}
  • self

Keyword for recursively refering to the current object

Example:

package Cat {
    use Pudu;

    has name => ( is => 'ro' );

    method speak => sub {
        "Meow... my name is " . self->name;
    };
}
  • is

Keyword for establishing an 'is a' relationship between a child class and it's parents.

Example:

package Point3D {
    use Pudu;
    is 'Point';
}
  • does

Keyword for establishing a 'does' relationship between a class and a Role.

NOTE: this does not work yet

Example:

package LazyList {
    use Pudu;
    does 'Enumerable';
}
  • private

Keyword for designating a private scope

Example:

package Cat {
    use Pudu;

    private {
        method hide => sub {
            "hidden"
        };
    };
}

Cat->new->hide; # dies
  • protected

Keyword for designating a protected scope

Example:

package Animal {
    use Pudu;

    protected {
        method share => sub {
            "I share with my friends"
        };
    };
}

package Cat {
    use Pudu;
    is 'Animal';

    method reveal => sub {
        self->share . " and with strangers"
    };
}

Animal->new->share; # dies
Cat->new->reveal;   # => "I share with my friends and with strangers"
  • method

Keyword for defining a method

Example:

package Dog {
    use Pudu;

    method speak => sub {
        "bark"
    };
}

AUTHOR

Delon Newman [email protected]

SEE ALSO

Moose, Mouse, Moo, Mo, Class::Closure, Devel::EnforceEncapsulation

pudu's People

Contributors

delonnewman avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.