Almost-minimal filesystem based blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.3 KiB

  1. #!/usr/bin/env perl
  2. =pod
  3. =head1 NAME
  4. wrt-repl - simple read-eval-print loop for wrt's inner workings
  5. =head1 USAGE
  6. wrt repl
  7. =head1 DESCRIPTION
  8. Uses Term::ReadLine to provide a live interface to a loaded wrt environment for
  9. the current working wrt directory.
  10. This is primarily a debugging tool for the current wrt implementation itself.
  11. Detailed documentation can be found in the L<App::WRT> man page or at
  12. L<https://code.p1k3.com/gitea/brennen/wrt>.
  13. =head1 LICENSE
  14. wrt is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; either version 2 of the License, or
  17. (at your option) any later version.
  18. =head1 AUTHOR
  19. Brennen Bearnes <code@p1k3.com>
  20. =cut
  21. use 5.10.0;
  22. use strict;
  23. use warnings;
  24. use utf8;
  25. use open qw(:std :utf8);
  26. use Getopt::Long qw(GetOptionsFromArray);
  27. use Pod::Usage;
  28. use App::WRT;
  29. use Carp;
  30. use Term::ReadLine;
  31. use Data::Dumper;
  32. $Carp::Verbose = 1;
  33. if (not caller()) {
  34. main(@ARGV);
  35. exit(0);
  36. }
  37. sub main {
  38. my (@local_argv) = @_;
  39. # Handle options, including help generated from the POD above. See:
  40. # - http://perldoc.perl.org/Getopt/Long.html#User-defined-subroutines-to-handle-options
  41. # - https://metacpan.org/pod/Pod::Usage
  42. # - http://michael.thegrebs.com/2014/06/08/Pod-Usage/
  43. my $config_file = 'wrt.json';
  44. GetOptionsFromArray(
  45. \@local_argv,
  46. 'config=s' => \$config_file,
  47. help => sub { pod2usage(0) },
  48. ) or pod2usage(2);
  49. my $term = Term::ReadLine->new('wrt repl');
  50. my $OUT = $term->OUT || \*STDOUT;
  51. print $OUT "loading configuration from $config_file\n";
  52. my $w = App::WRT::new_from_file($config_file);
  53. print $OUT $w->{entry_dir} . ":\n";
  54. print $OUT "\t" . scalar($w->{entries}->all()) . " items\n";
  55. print $OUT "\t" . scalar($w->{entries}->all_renderable())
  56. . " renderable entries\n\n";
  57. print $OUT "Available:\n\t\$w\n";
  58. print $OUT "\t\$w->{entries}\n";
  59. print $OUT "\tDumper(\$foo)\n";
  60. print $OUT "\n";
  61. my $prompt = "wrt :: $w->{title_prefix} :: ";
  62. while ( defined ($_ = $term->readline($prompt)) ) {
  63. my $result = eval($_);
  64. carp $@ if $@;
  65. print $OUT $result, "\n" unless $@;
  66. $term->addhistory($_) if /\S/;
  67. $prompt = "wrt :: $w->{title_prefix} :: ";
  68. }
  69. }
  70. 1;