Let's imagine we have a client for some kind of API, json-based REST API to be more specific
Objects returned by that API are stored as Moose-compatible objects. Sometimes server provides full set of object data (when you ask for object directly). Sometimes not (when object returned as a part of complex request, usually provided just for reference. Like that
{ "article": { "author": { "id": "12345", "display_name": "Swami Dhyan Nataraj" } } }
In this example "author" section has minimal information, that is presumably needed for displaying the article. Though if you request full info for person with "12345" id you will get much more info, including "address" for example
I would expect perl implementation of API to work like this:
my $article = $client->article($article_id); my $addr = $article->author->address;
To do this, "address" method should fetch missing information from the server when it is needed. I would call it Lazy Fetching (BTW, do you know proper name for it?)
Two more questions...
First: I guess this lazy fetching can be implemented as Moose::Role, so you need to write method that knows how to refetch object, provide this method to the object's constructor (LazyFetch Role will know how to deal with it), and mark attributes that are due for lazy fetching. I tried to find such role in CPAN, but did not succeed. Did I miss it? May be there are some implementations that are not Moose one?
Second: Have you seen this concept of Lazy Fetching implemented anywhere else? Not in perl at all. I would hardly believe that I am first to whom this idea came into mind...
Update:P.S.This question is part of bigger project. Previous, may be related questions are Framework for making Moose-compatible object from json, One module to use them all (proxy moudle that exports subs of other modules)
In reply to Lazy fetching role for API clients' objects by nataraj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |