Posts with the tag perl:
Moose interfaces are problematic, for 2 reasons.
They are compile time, but runtime features such as attribute delegation could provide the interface (role ordering is the real problem here) They don’t ensure anything other than the method name. I think this problem can be solved better by using around instead of requires
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package Interface::Create; use Moose::Role; use Type::Params qw( compile ); use Types::Standard qw( slurpy HashRef); around create => sub { my $orig = shift; my $self = shift; state $check = compile( slurpy HashRef ); my ( $obj_args ) = $check->( @_ ); return $self->$orig( $obj_args ); }; 1; Ordering of course still matters here as you can have multiple around modifiers on a method.
If you’re not familiar with the term “Inversion of Control”( IoC ) or “Dependency Injection” ( DI )you may wish to start with Martin Fowler’s post on the subject. If you’re looking for a way to do it with Perl, Bread::Board is the way to go. This post however is about the theory behind it, and a path to grokitude if you’re finding the concepts challenging. I should advise that I am not yet a buddha on implementation.
What is Interface Driven Design? Interface Driven Design simply means that you should design your software around a flexible, easy to use, easy to understand interface. This is easy to achieve if your objects are of SOLID design. There is a simple table and reference link if you’re not familiar with the principles.
My Work is SOLID already Then you’re on the right track but it’s not enough if you don’t fully marry the concept to best practices.
2012-07-24
2021-08-10
perl
Per the 5.12 release announcement
This release cycle marks a change to a time-based release process. Beginning with version 5.11.0, we make a new development release of Perl available on the 20th of each month. Each spring, we will release a new stable version of Perl. One month later, we will make a minor update to deal with any issues discovered after the initial “.0” release. Future releases in the stable series will follow quarterly.
I want to see Role’s added, even PHP got Traits before Perl. It doesn’t have to be a huge thing, in fact all I want is the composition aspect. Let me do this:
1 2 3 4 5 6 7 8 9 package MyRole { sub foo { return 'test' } } package MyClass { with 'MyRole'; ... } MyClass->new->foo; I don’t really want or need anything else right now, just that would be fine.
I would like to see the classkeyword become part of Perl, but unlike some I don’t want it simply because it’s nicer syntax. I’d like it to behave differently from package. I’d basically like to see this class MyClass {method foo { return $self->{foo} }method info { return load_class(‘Class::Info’)->new }}to be the equivalent of {use strict;use warnings;use utf8; # so our class can be named with utf8package MyClass {use namespace::autoclean;use Scalar::Util qw( blessed );# use Class::Load qw( load_class );# or similar for a feature that I’m hoping will be in Class::Load in the future# for now I’ll show with requiresub new { # or something better, point is that there’s a default simple constructormy $class = shift;my $self = ref $[0] eq ‘HASH’ ?
So I’ve done some complaining and explaining about what I’d like to see in regards to Exceptions in Perl. I Mostly explained what I wanted for catching Exceptions, and a little on throwing Exception objects, but not really how those objects should behave. I’ve looked at and tried various exception modules, including croak, confess, and Throwable. I basically spent time one day reading the manuals of most of the exception objects on CPAN.
I hate die it is, in my humble opinion, one of the worst parts of perl. I really wish it would be deprecated, and removed, or at least replaced with something that would tell you were the code that was die-ing was being called. Replace its implementation with that of Carp’s croak or confess and I’d be happy. Better yet, let’s just get real exception support and deprecate die (even if that’s never removed deprecation just make that real big on its pod).