Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ap/object-tiny-lvalue
minimal class builder with lvalue accessors
https://github.com/ap/object-tiny-lvalue
object-oriented-programming oop perl
Last synced: 10 days ago
JSON representation
minimal class builder with lvalue accessors
- Host: GitHub
- URL: https://github.com/ap/object-tiny-lvalue
- Owner: ap
- Created: 2009-12-08T14:56:24.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2022-09-04T15:48:37.000Z (over 2 years ago)
- Last Synced: 2024-11-06T03:03:50.407Z (about 2 months ago)
- Topics: object-oriented-programming, oop, perl
- Language: Perl
- Homepage: https://metacpan.org/release/Object-Tiny-Lvalue
- Size: 31.3 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.pod
- Changelog: Changes
Awesome Lists containing this project
README
use 5.006; use strict; use warnings;
package Object::Tiny::Lvalue;
our $VERSION = '1.084';
sub import {
return unless shift eq __PACKAGE__;
my $pkg = caller;
eval join "\n", (
"package $pkg;",
'our @ISA = "Object::Tiny::Lvalue" unless @ISA;',
map {
defined and /\A[^\W\d]\w*\z/ or die "Invalid accessor name '$_'";
"sub $_ : lvalue { \$_[0]->{$_} }";
} @_
);
die "Failed to generate $pkg" if $@;
return 1;
}sub new {
my $class = shift;
bless { @_ }, $class;
}1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Object::Tiny::Lvalue - minimal class builder with lvalue accessors
=head1 SYNOPSIS
Define a class:
package Foo;
use Object::Tiny::Lvalue qw( bar baz );
1;Use the class:
my $object = Foo->new( bar => 1 );
printf "bar is %s\n", $object->bar;
$object->bar = 2;
printf "bar is now %s\n", $object->bar;=head1 DESCRIPTION
This is a clone of L, but adjusted to create accessors that return lvalues.
You probably want to use L instead.
=cut