The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojolicious::Plugin::Notifications::Engine - Abstract Class for Notification Engines

SYNOPSIS

  package Mojolicious::Plugin::Notifications::MyEngine;
  use Mojo::Base 'Mojolicious::Plugin::Notifications::Engine';

  # Define notifications helper
  sub notifications {
    my ($self, $c, $notifications) = @_;

    my $string = '';
    foreach (@$notifications) {
      $string .= '<blink class="' . $_->[0] . '">' . $_->[-1] . '</blink>';
    };
    return $c->b($string);
  };

DESCRIPTION

Mojolicious::Plugin::Notifications::Engine is an abstract class for creating notification engines. It is meant to be used as the base of notification engine classes.

METHODS

Mojolicious::Plugin::Notifications::Engine inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

  sub register {
    my ($self, $app, $param) = @_;
    # ...
  };

Called when the engine is registered. This by default does nothing, but the engine may define assets, helpers, hooks etc. overriding this method. The optional parameter will be passed as defined in the registration.

scripts

  $self->scripts('/mybasescript.js', '/myscript.js');
  print $self->scripts;

Add further script assets, to be used by the scripts helper.

styles

  $self->styles('/mystyles.css', '/mycolors.css');
  print $self->styles;

Add further style assets, to be used by the styles helper.

notifications

  # Define notifications method
  sub notifications {
    my ($self, $c, $notifications) = @_;

    my $string = '';
    foreach (@$notifications) {
      $string .= '<blink class="' . $_->[0] . '">' . $_->[-1] . '</blink>';
    };
    return $c->b($string);
  };

Create a notification method.

The notifications method will be called whenever notifications are rendered. The first parameter passed is the plugin object, the second parameter is the current controller object and the third parameter is an array reference containing all notifications as array references.

The first element of the notification is the notification type, the last element is the message. An optional second element may contain further parameters in a hash reference.

  %= notifications 'MyEngine', -no_include

Possible flags (boolean parameters marked with a dash) are passed as a hash reference. All other parameters passed to the notifications helper are simply appended.

The bundled engines can serve as good examples on how to write an engine, especially the simple HTML engine.

AVAILABILITY

  https://github.com/Akron/Mojolicious-Plugin-Notifications

COPYRIGHT AND LICENSE

Copyright (C) 2014-2015, Nils Diewald.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.