Venus::Prototype - Prototype Class
Prototype Class for Perl 5
package main; use Venus::Prototype; my $prototype = Venus::Prototype->new( '$counter' => 0, '&decrement' => sub { $_[0]->counter($_[0]->counter - 1) }, '&increment' => sub { $_[0]->counter($_[0]->counter + 1) }, ); # bless({value => {...}}, 'Venus::Prototype') # $prototype->counter # 0 # $prototype->increment # 1 # $prototype->counter # 1 # $prototype->decrement # 0 # $prototype->counter # 0
This package provides a simple construct for enabling prototype-base programming. Properties can be called as methods when prefixed with a dollar or ampersand symbol. See "call" for more details.
This package inherits behaviors from:
Venus::Kind::Utility
This package integrates behaviors from:
Venus::Role::Buildable
Venus::Role::Proxyable
Venus::Role::Valuable
This package provides the following methods:
apply(HashRef $data) (Prototype)
The apply method extends the underlying data structure by merging the data provided, and then returns the invocant.
Since 1.50
1.50
package main; my $person = Venus::Prototype->new({ '$name' => '', }); $person->apply; # bless({value => {'$name' => ''}}, 'Venus::Prototype')
package main; my $person = Venus::Prototype->new({ '$name' => '', }); $person->apply({ '$name' => 'Elliot Alderson', }); # bless({value => {'$name' => 'Elliot Alderson'}}, 'Venus::Prototype')
package main; my $person = Venus::Prototype->new({ '$name' => '', '&greet' => sub {'hello'}, }); $person->apply({ '$name' => 'Elliot Alderson', }); # bless({value => {...}}, 'Venus::Prototype')
call(Str $method, Any @args) (Any)
The call method dispatches method calls based on the method name provided and the state of the object, and returns the results. If the method name provided matches an object property of the same name with an ampersand prefix, denoting a method, then the dispatched method call acts as a method call providing the invocant as the first argument. If the method name provided matches an object property of the same name with a dollar sign prefix, denoting an attribute, then the dispatched method call acts as an attribute accessor call. This method is also useful for calling virtual methods when those virtual methods conflict with the Venus::Prototype methods.
package main; my $person = Venus::Prototype->new({ '$name' => 'anonymous', }); my $name = $person->call('name'); # "anonymous"
package main; my $person = Venus::Prototype->new({ '$name' => 'anonymous', }); my $name = $person->call('name', 'unidentified'); # "unidentified"
extend(HashRef $data) (Prototype)
The extend method copies the underlying data structure, merging the data provided if any, and then returns a new prototype object.
package main; my $mrrobot = Venus::Prototype->new({ '$name' => 'Edward Alderson', '$group' => 'fsociety', }); my $elliot = $mrrobot->extend({ '$name' => 'Elliot Alderson', }); # bless({value => {...}}, 'Venus::Prototype')
package main; my $mrrobot = Venus::Prototype->new({ '$name' => 'Edward Alderson', '$group' => 'fsociety', '$login' => { username => 'admin', password => 'secret', }, }); my $elliot = $mrrobot->extend({ '$name' => 'Elliot Alderson', '$login' => { password => '$ecr3+', }, }); # bless({value => {...}}, 'Venus::Prototype')
package main; my $ability = { '&access' => sub {time}, }; my $person = Venus::Prototype->new; my $mrrobot = $person->extend($ability); my $elliot = $mrrobot->extend($ability); # bless({value => {...}}, 'Venus::Prototype')
Awncorp, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2000, Al Newkirk.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.