Rubyish::AttributeRuby-like accessor builder | |
Download |
Rubyish::Attribute Ranking & Summary
Advertisement
- License:
- MIT/X Consortium Lic...
- Price:
- FREE
- Publisher Name:
- shelling
- Publisher web site:
- http://search.cpan.org/~shelling/
Rubyish::Attribute Tags
Rubyish::Attribute Description
Ruby-like accessor builder Rubyish::Attribute is a Ruby-like accessor builder: attr_accessor, attr_writer and attr_reader.SYNOPSIS #!/usr/bin/env perl use 5.010; use strict; use warnings; { package Animal; use Rubyish::Attribute; # import attr_accessor, attr_writer and attr_reader BEGIN { attr_accessor "name", "color", "type"; } # pass a list as the only one parameter # invoke it in compile time to avoid using parenthesis when using instance variable as below # then create a constructer based on hashref sub new { $class = shift; bless {}, $class; } sub rename_as { my ($self, $new_name) = @_; __name__ = $new_name; # __name__ is accurately a lvalue subroutine &__name__() which refer to $self->{name} # now it looks like a instance variable. } 1; } $dogy = Animal->new()->name("rock") ->color("black")->type("unknown"); # new Animal with three attribute say $dogy->name; #=> rock say $dogy->color; #=> black say $dogy->type; #=> unknown Requirements: · Perl
Rubyish::Attribute Related Software