0

I have been looking through the spice instant answer source code. Yes, I know it is in maintenance mode, but I am still curious.

The documentation makes it fairly clear that the primary spice to API gets its numerical parameters $1, $2, etc. from the handle function.

My question: should there be secondary API calls included with spice alt_to as, say, in the movie spice IA, where do the numerical parameters to that API call come from?

Note, for instance, the $1 in both the movie_image and cast_image secondary API calls in spice alt_to at the preceding link. I am asking which regex capture returns those instances of $1.

grobber
  • 1,083
  • 1
  • 9
  • 20

1 Answers1

1

I believe I see how this works now. The flow of information is still a bit murky to me, but at least I see how all of the requisite information is there.

I'll take the cryptocurrency instant answer as an example. The alt_to element in the perl package file at that link has a key named cryptonator. The corresponding .js file constructs a matching endpoint:

var endpoint = "/js/spice/cryptonator/" + from + "/" + to;

Note the general shape of the "remainder" past /js/spice/cryptonator: from/to, where from and to will be two strings.

Back in the perl package the hash alt_to->{cryptonator} has a key from which receives, I think, this remainder from/to. The value corresponding to that key is a regex meant to split up that string into its two constituents:

from => '([^/]+)/([^/]*)'

Applied to from/to, that regex will return $1=from and $2=to. These, then, are the $1 and $2 that go into

to => 'https://api.cryptonator.com/api/full/$1-$2'

in alt_to.


In short:

The to field of alt_to->{blah} receives its numerical parameters by having the from regex operate on the remainder past /js/spice/blah/ of the name of the corresponding endpoint constructed in the relevant .js file.

grobber
  • 1,083
  • 1
  • 9
  • 20