Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 961973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:25:59+00:00 2026-05-16T01:25:59+00:00

We are trying to build an API to support commit() and rollback() automatically, so

  • 0

We are trying to build an API to support commit() and rollback() automatically, so that we don’t have to bother with it anymore. By researching, we have found that using eval {} is the way to go.

For eval {} to know what to do, I have thought of giving the API an array of functions, which it can execute with a foreach without the API having to intepret anything. However, this function might be in a different package.

Let me clarify with an example:

sub handler {
    use OSA::SQL;
    use OSA::ourAPI;
    my @functions = ();
    push(@functions, OSA::SQL->add_page($date, $stuff, $foo, $bar));
    my $API = OSA::ourAPI->connect();
    $API->exec_multi(@functions);
}

The question is: Is it possible to execute the functions in @functions inside of OSA::ourAPI, even if ourAPI has no use OSA::SQL. If not, would it be possible if I use an array reference instead of an array, given that the pointer would point to the known function inside of the memory?

Note: This is the basic idea that we want to base the more complex final version on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:26:00+00:00Added an answer on May 16, 2026 at 1:26 am

    • You are NOT adding a function pointer to your array. You are adding teh return value of calling the add_page() subroutine. You have 3 solutions to this:

      A. You will need to store (in @functions) an array of arrayrefs of the form [\&OSA::SQL::add_page, @argument_values], meaning you pass in an actual reference to a subroutine (called statically); and then exec_multi will do something like (syntax may not be 100% correct as it’s 4am here)

      sub exec_multi {
          my ($class, $funcs)= @_;
          foreach my $f (@$funcs) {
              my ($func, @args) = @$f;
              my $res = &$func(@args);
              print "RES:$res\n";
          }
      }
      

      Just to re-iterate, this will call individual subs in static version (OSA::SQL::add_page), e.g. WITHOUT passing the package name as the first parameter as a class call OSA::SQL->add_page would. If you want the latter, see the next solution.


      B. If you want to call your subs in class context (like in your example, in other words with the class name as a first parameter), you can use ysth’s suggestion in the comment.

      You will need to store (in @functions) an array of arrayrefs of the form [sub { OSA::SQL->add_page(@argument_values) }], meaning you pass in a reference to a subroutine which will in turn call what you need; and then exec_multi will do something like (syntax may not be 100% correct as it’s 4am here)

      sub exec_multi {
          my ($class, $funcs)= @_;
          foreach my $f (@$funcs) {
              my ($func) = @$f;
              my $res = &$func();
              print "RES:$res\n";
          }
      }
      

      C. You will need to store (in @functions) an array of arrayrefs of the form [ "OSA::SQL", "add_page", @argument_values], meaning you pass in a package and function name; and then exec_multi will do something like (syntax may not be 100% correct as it’s 4am here)

      my ($package, $sub, @args) = @{ $functions[$i] };
      no strict 'refs';
      $package->$sub(@args);
      use strict 'refs';
      

    • If I understood your question correctly, then you don’t need to worry about whether ourAPI uses OSA::SQL, since your main code imports it already.

      However, since – in #1B – you will be passing a list of packages to exec_multi as first elements of each arrayref, you can do “require $package; $package->import();” in exec_multi. But again, it’s completely un-necessary if your handler call already required and loaded each of those packages. And to do it right you need to pass in a list of parameters to import() as well. BUT WHYYYYYY? 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 487k
  • Answers 487k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I found it actually concerns only modules who modify data… May 16, 2026 at 8:21 am
  • Editorial Team
    Editorial Team added an answer protected methods can be called by any instance of the… May 16, 2026 at 8:21 am
  • Editorial Team
    Editorial Team added an answer RANK, rather than ROW_NUMBER, because you want ties (those with… May 16, 2026 at 8:21 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Related Questions

No related questions found

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.