Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add consecrate method as a higher level constructor method, -oil to return "object in line" but leave constructor hanging around for additional use #8

Open
oodler577 opened this issue Dec 12, 2023 · 1 comment
Assignees

Comments

@oodler577
Copy link
Owner

oodler577 commented Dec 12, 2023

consecrate q{My::Foo}, qw/guaranteed list of accessors and methods/;
*My::Foo::something_else  = sub { ... };  # just use well known Perl idiom for adding or replacing subs
*My::Foo::another_methods = \&subroutine_already_defined;  # just use ...

Should generate a MY::FOO::new package constructor equivalent to all that;s needed by folks 99% of the time:

sub new {
  my ($pkg, %opts) = @_;
  my $self = \%opts;
  baptise \%opts, $pkg;
  return $self;
}

Adding the efficiency of creating an object in line ..

my $object = consecrate -oil, q{My::Foo}, qw/guaranteed list of accessors and methods/;
...
my $object2 = My::Foo->new(...);

should be return an instantiated object and also keep the package constructor around

@oodler577
Copy link
Owner Author

Interesting idea, but since I created this issue I have not yet run into a situation where this was my "go-to" solution.

@oodler577 oodler577 self-assigned this Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant