Pavel, you can do this: my $b = __PACKAGE__->can($a); $b->("stuff") if $code;
You can replace __PACKAGE__ with whatever package name you want. The special symbol "__PACKAGE__" contains the current package, can() returns a ref to a function/method if $a has the correct method name which can be found in the class or any of the inherited classes. On Friday, December 12, 2014 8:12:36 PM UTC+1, Pavel Serikov wrote: > > Hi Sebastian, > > Thank you very much. > > Actually working solution is: > my $a = "test"; > sub test { > print "Hello World!\n"; > } > my $b = \&$a; > $b->(); > > I hope that this code is considered as good style :) > > And the real question that needs to be answered first is "What are you >> actually trying to achieve?". > > > Actually I am writing some helpers for working with one API. Example > below shows why i need to use function name as parameter (string): > > sub api_abstraction { > my ($timeout, $params, $is_form, $name_of_parse_function, $is_render) > = @_; > # ... > my $a = \&$name_of_parse_function; > $a->(); > } > > sub parser1 { > print "Hello World!\n"; > # ... > } > > sub parser2 { > print "Obama eats children!\n"; > # ... > } > > my $hash = api_abstraction(7, {product => 'phone', sn => '0001'}, 1, > 'parser2', 1); > > > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at http://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.