Perl - references
Let's remove all simple data-structures like @lists and %hashes. When we think "list" let use list-refs, ref-hashes instead of hashes. Let's keep only scalars and references with implicit dereferencing, like in Python or Ruby. No wantarray context-dependent behaviour! No @{$foo} and \@foo and other nasty code! Perl will be clear and more funny!
current perl:
$foo = [ map { ... } @$bar ]
better perl:
$foo = map { } $bar
As I see folks have problems why we write:
%hash = (foo => 42);
$hash{foo} # where is hash sign, % ?
@list = qw/foo bar baz/;
$list[1] # where is list sign, @ ?
and there is no much difference between lists and refs, but differences between various forms of using refs are probably bigger than list<->ref:
$list[1][2] # wolf
$$list[1][2] # dog1
$list->[1][2] # dog2
$list->[1]->[2] # dog3
Sure, there is only one dog, welcome to TIMTOWDI world!
There are also some troubles with
$ref = \@list;
$ref = [@ref]
# maybe it is @list?
$ref = [ $some->method ]
# or maybe it is %hash?
$ref = { $some->method }
# could be better to make something like
$ref = $some->method->return_as_hashref
$ref = $some->method->return_as_arrayref
Maybe I should stop writing perl code because I think too much about all those things? ;)
Catalyst - index is different than other actions
What is a difference between:
Controller app::foo;
sub index : Private {
my ($self, $c, $param1) = @_;
}
sub show : Local {
my ($self, $c, $param1) = @_;
}
?
Index will not catch arguments, will not work with /foo/123, although /foo/show/123 will work that way. To fix index, we need to use LocalRegex
sub index : LocalRegex('^(.*)$') {
my ( $self, $c ) = @_;
my ($param1) = @{ $c->req->captures };
}
No comments:
Post a Comment