This section contains a few bits of code for things you might want to do with Plugins.
# Import the LRR logging moduleuse LANraragi::Utils::Logging qw(get_logger);# Use the logger to output status - they'll be passed to a specialized logfile and written to STDOUT.my $logger = get_logger("MyPluginName","plugins");​$plugin->debug("This message will only show if LRR is in Debug Mode")$plugin->info("You know me the fighting freak Knuckles and we're at Pumpkin Hill");$plugin->warn("You ready?");$plugin->error("Oh no");
The logger is a preconfigured Mojo::Log object.
​Mojo::UserAgent is a full-featured HTTP client coming with LRR you can use.
use Mojo::UserAgent;​my $ua = $lrr_info->{user_agent};​#Get HTML from a simple GET request$ua->get("http://example.com")->result->body;​#Make a POST request and get the JSON resultmy $rep = $ua->post("https://jsonplaceholder.typicode.com/" => json => {stage => "Meteor Herd",location => [ [ "space", "colony" ] ],emeralds => 3})->result;​#JSON decoded to a perl objectmy $jsonresponse = $rep->json;​#JSON decoded to a stringmy $textrep = $rep->body;
my $redis = LANraragi::Model::Config->get_redis;​my $value = $redis->get("key");
This uses the excellent Perl binding library for Redis.
If you're running 0.5.2 or later:
use LANraragi::Utils::Archive qw(is_file_in_archive extract_file_from_archive);​#Check if info.json is in the archive located at $fileif (is_file_in_archive($file,"info.json")) {​#Extract info.jsonmy $filepath = extract_file_from_archive($file, "info.json");​#Do whatever you need with the extracted fileopen( my $fh, '<:encoding(UTF-8)', $filepath )or return ( error => "Could not open $filepath!" );​while ( my $row = <$fh> ) {#...}​#Delete itunlink $filepath;}