in reply to Re: Module design for loadable external modules containing data
in thread Module design for loadable external modules containing data
maybe I'm too much confused, but the interesting module File::ShareDir you suggested to me does not solve my doubts. If I read it correctly (and just glanced it atm) it is used to share and expose pure data stored at install time somewhere in the filesystem and make the program to be able to find them at runtime. My situation is more complex, or I'm too blind to see a clean solution.
Maybe a rough piece of pseudocode will show it better:
# # modules of my distribution: # Perl::Teacher load_course (then in the program using this module I can call $course +->get_description) load_lesson (then in the program using this module I can call $lesson +->get_steps) Perl::Teacher::Course new creates a slot for description and one for [lessons] get_description get_lessons Perl::Teacher::Lesson new creates a slot for abstract and one for [steps] get_abstract get_steps # # modules outside my distribution, intended to be written by someone e +lse and installed separately # (note that these modules should have their own tests under /t folder + as any module should) # Perl::Teacher::Course::EN::PerlIntro isa Perl::Teacher::Course $__PACKAGE__::description = 'a fair intro to perl', $__PACKAGE__::lessons = [Perl::Teacher::Course::EN::PerlIntro::01_for +eword , ...] Perl::Teacher::Course::EN::PerlIntro::01_strictures isa Perl::Teacher::Lesson $__PACKAGE__::abstract = 'introducing the safety net' $__PACKAGE__::steps = [ # a simple text 001=>{type=>text,content=>'We now introduce strictures'}, # check_script_compiles is a method exposed by Perl::Teacher 002=>{ name=>'script compiles', action=>\check_script_compiles() } # a complex test to be run against student's code 003=>{type=>test,content=>{ name => 'strictures', # select_child_of is a method exposed by Perl::Teacher select_child_of => { class => 'PPI::Statement::Include', tests => [ ['PPI::Token::Word', qr/^use$/], ['PPI::Token::Word', 'strict'] ], }, hint => "search perlintro for safety net", docs => ['https://perldoc.perl.org/perlintro.html#Safet +y-net'], } } ]
As you can see it is very ugly. I'd like to provide a nice and usable interface to course authors.
One solution I have is to abstract as much as possible the lesson content and provide an higher level language to define a lesson, probably YAML will be enough. I dont like very much this solution because it will force the author to write YAML instead of perl code. If I go for YAML then File::ShareDir can be an option: the Perl::Teacher::Course::EN::PerlIntro simply write 01_strictures.yaml to the disk then the Perl::Teacher object load the course and all its yaml from the disk.
Thanks for the help!
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Module design for loadable external modules containing data
by kcott (Archbishop) on Oct 16, 2020 at 01:16 UTC | |
|
Re^3: Module design for loadable external modules containing data
by Anonymous Monk on Oct 17, 2020 at 19:33 UTC |