NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Curious... (Score:1)
.... why the trailing "no Moose"?
Re: (Score:2)
It removed the functions that Moose exports into your package. It would be annoying if someone tried to call $object->has :)
Re: (Score:2)
The lovely MooseX::Declare [cpan.org] lets you avoid even that (and it's an incredible module), but unfortunately, it's very alpha and has plenty of bugs. Still, look what it buys you:
Re: (Score:1)
> I can't wait until that's production ready.
Ohhh. Shiny! :-)
Re: (Score:1)
All MooseX::Declare does to not require you to unimport all Moose keywords (and possibly other imports) is
use namespace::clean -except => 'meta';to remove all previously defined and imported functions (except for the 'meta' method Moose gives you) at the end of compile time. No need to wait for anything.
Re: (Score:1)
I can't wait until that's production ready.
I think everyone who left the London Perl tech talk last night felt & thought the exactly same thing.
Patience is a virtue!
/I3az/
What about ''? (Score:2)
I don't understand the bit about the final '' in your comment. I think a better way to do that is make method lazy and have the default be:
sub { $_[0]->name }
Re: (Score:2)
The reason for the final '' is that it put a string in the method, thus ensuring it would pass type validation. Your solution is much nicer. Thanks :)
Ohh, Moose Golf! (Score:1)
So, in the interest of TIMTOWTDI, here is another approach that uses coercion to extract the params list from the controller object.
A code smell (Score:2)
Thinking about this example, there's a code smell in general with your use of BUILDARGS.
BUILDARGS is really _not_ for munging arguments, it's there to allow for a constructor which doesn't take named argument, like
my $user = User->new($user_id);
If you're using it to add extra arguments, consider using lazy default/builder, per my suggestion. If you're using it to coerce, use a coercion per Stevan's example.
Re: (Score:2)
OK, I'll buy the code smell argument because you have more experience with this than I do, but I don't understand. I like the lazy/default example, but Stevan's example is longer than mine and doesn't seem to buy me anything. Plus, as Stevan pointed out, it has the drawback of an apparently misnamed constructor pair. What am I missing?
Re: (Score:2)
The advantage of coercion is exactly what Stevan says, it lets you reuse that bit of logic across classes.
The name mismatch is weird, but I'd probably just have people call the constructor like this:
PIPs::QueryParams->new( params => $controller->allowed_query_params );
I honestly don't like _any_ of these options much myself, but I don't understand your APIs or problem domain well enough to come up with a better solution.
There's just something about using BUILDARGS to do what coercion can do that st