I can't seem to get to figure out how to pass hashrefs to a module correctly.
#module helper.pm
my %helpers;
sub import {
shift @_; #returns "helper"
%SOME_CONFIG = %{shift @_};
foreach my $hashref (%{@_}){
$helpers{$hashref->{key}} = $hashref->{value};
}
}
#main
use helper(
\%SOME_CONFIG,
"first_helper" => (
sub {
return do_something();
},
sub {
return do_something_else();
}
),
"second_helper" => (
sub {
return something_else();
}
)
);
I'm not sure how to convert the array to a hash correctly. I thought it work because the anonymous function are passed as references. However it still indexes over @_ as if it is an array and the keys become the indexes of @_.