https://github.com/awncorp/data-object-role-buildable
Buildable Role for Perl 5
https://github.com/awncorp/data-object-role-buildable
object-oriented perl perl5
Last synced: 6 days ago
JSON representation
Buildable Role for Perl 5
- Host: GitHub
- URL: https://github.com/awncorp/data-object-role-buildable
- Owner: awncorp
- License: other
- Created: 2020-10-03T19:05:21.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-03T20:34:41.000Z (over 5 years ago)
- Last Synced: 2025-11-10T18:13:18.034Z (8 months ago)
- Topics: object-oriented, perl, perl5
- Language: Perl
- Size: 24.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: CHANGES
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
NAME
Data::Object::Role::Buildable
ABSTRACT
Buildable Role for Perl 5
SYNOPSIS
package Vehicle;
use Moo;
with 'Data::Object::Role::Buildable';
has name => (
is => 'rw'
);
1;
DESCRIPTION
This package provides methods for hooking into object construction of
the consuming class, e.g. handling single-arg object construction.
SCENARIOS
This package supports the following scenarios:
buildarg
package Car;
use Moo;
extends 'Vehicle';
sub build_arg {
my ($class, $name) = @_;
# do something with $name or $class ...
return { name => $name };
}
package main;
my $car = Car->new('tesla');
This package supports handling a build_arg method, as a hook into
object construction, which is called and passed a single argument if a
single argument is passed to the constructor.
buildargs
package Sedan;
use Moo;
extends 'Car';
sub build_args {
my ($class, $args) = @_;
# do something with $args or $class ...
$args->{name} = ucfirst $args->{name};
return $args;
}
package main;
my $sedan = Sedan->new('tesla');
This package supports handling a build_args method, as a hook into
object construction, which is called and passed a hashref during object
construction.
buildself
package Taxicab;
use Moo;
extends 'Sedan';
sub build_self {
my ($self, $args) = @_;
# do something with $self or $args ...
$args->{name} = 'Toyota';
return;
}
package main;
my $taxicab = Taxicab->new('tesla');
This package supports handling a build_self method, as a hook into
object construction, which is called and passed a hashref during object
construction. Note: Manipulating the arguments doesn't effect object's
construction or properties.
AUTHOR
Al Newkirk, awncorp@cpan.org
LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under
the terms of the The Apache License, Version 2.0, as elucidated in the
"license file"
.
PROJECT
Wiki
Project
Initiatives
Milestones
Contributing
Issues