Skip to content

New modules (addons) — integration notes

Basics

New modules (addons) are extensions points to add extra functionality to Pheix. Technically speaking addons should be just Raku modules.

Addon generic requirements:

  1. Installation as Raku module via zef;
  2. Configuration in config.json file;
  3. Each addon should provide Pheix::Addons::ModuleName and Pheix::Addons::ModuleName::API.

Breaking changes

Add $addon optional argument to fill_seodata() method:
method fill_seodata(Str :$pg_addon, Str $pg_type) {
    ...
    given $pg_type {
        when 'debug' {
            ;
        }
        when '404' {
            %h.append({m => 'Pheix' !!, t => '404'});
        }
        default {
            %h.append(
                {
                     m => ($pg_addon eq q{}) ?? 'Pheix' !! $pg_addon,
                     t => $pg_type
                }
            );
        }
    }
    ...
}
Update show_pg method for Phiex::View::Pages:
  1. Add $pg_addon optional argument fill_seodata() method:
method show_pg(
    Str  :$pg_addon,
    Str  :$pg_type!,
    Str  :$pg_route!,
    Str  :$pg_content,
         :%pg_env
) returns Str { ... }
  1. Call fill_seodata() method with $pg_addon argument:
self.fill_seodata(:pg_addon($pg_addon // 'Pheix'), :pg_type($pg_type));
Update given block at show_pg() method in Phiex::View::Pages:
  • Make current default block as when 'debug' { ... };
  • Make when 'index' { ... } block as default { ... };
  • Update debug calls to show_pg method (grep -rwn "show_pg"):
    • lib/Pheix/Controller/Basic.rakumod:76;
    • lib/Pheix/Controller/Basic.rakumod:94;
    • lib/Pheix/Controller/Basic.rakumod:114;
    • t/18-pages.t:74;
    • t/18-pages.t:97.
Update Phiex::Model::JSON:

Add :conf() arg to group getters:

method get_setting(Str $addon, Str $setting, Str $key, Bool $nocache?, Str :$conf) returns Cool { ... };
method get_group_setting(Str $addon, Str $group, Str $setting, Str $key, Str :$conf) returns Cool { ... };
method get_all_settings_for_group_member(Str $addon, Str $group, Str $setting, Str :$conf) returns Hash { ... };

Module structure

Each addon should has:

  1. sharedobj attr (type Hash) as a container for sharedobj from Pheix::Controller::Basic;
  2. name attr (type Str):
has $.name = 'Weblog';
  1. jsonobj attr (type Pheix::Model::JSON) with module readonly configuration;
has $.jsonob = Pheix::Model::JSON.new(:addonpath('conf/addons')).set_entire_config(:addon($!name));
  1. genesis attr (type Hash) with module readonly configuration:
has %.genesis =
    version  => 0.0.1,
    routes   => $!jsonob.get_all_settings_for_group_member($!name, 'routing', 'routes')
;
  1. Handler methods (see routes config) for API rendering.
  2. Method for SEO tag import to configuration at initialization stage

Sample

https://gitlab.com/pheix-pool/core-perl6/-/blob/2a32436706e15b102e787f6cbad1be6ad0775234/lib/Pheix/Addons/Embedded/User.rakumod

Private database, SEO tags

Do we need conf/system/module.tnk?

More details: #106 (comment 459550707)

Edited by Konstantin Narkhov