Re: is there any "hello-world" demo for plugin-based application?



Tony Winslow <tonywinslow1986@xxxxxxxxx> writes:

We're building a document management system which supports multiple
types of documents. Thus, the editors for different documents vary
from one another. We would like to build the system in a plugin-based
style so that we or the users of it can add new document types to it
as needed. However, we don't know exactly how to implement it in a
plugin-based flavor. So we want to find some very simple and
easy-to-learn examples. Could anybody help? Thank you!

Plugins are generally implemented using normal perl modules implementing
some interface that works for your system. This probably means it's
easiest to implement using OO modules since that gives you inheritance
of base methods and a standardized way of referencing your plugins for
free.

here's a very simple example:

# in file MyPlugin.pm

package MyPlugin;

sub new {
return bless { name => "MyPlugin plugin" }, shift;
}

sub print_hello {
my ($self) = @_;
print "Hello from ",$self->{name},"\n";
}

1;

# in your main program:

# get this list from configuration
# or scan a predefined directory...
my @plugins = qw(MyPlugin);

foreach my $plugin (@plugins) {
eval "use $plugin" or die; # I prefer this over require ... import, YMMV
$plugin->new()->print_hello();
}

.



Relevant Pages

  • Re: Editor for Linux
    ... > their editors, and editors are completely personal, but I do like jEdit and ... Before you go questing for an IDE, take a long look at the available ... jEdit plugins. ... "Plugins can turn jEdit into a full-fledged IDE, with compiler, code ...
    (alt.os.linux.redhat)
  • Re: Best Linux Distributions, Software for Photo Processing?
    ... those rare few but worthwhile plugins that are written as Photoshop-Only. ... I despise Photoslop because it's one of the poorest editors ... The value which exists for the most high-end plug-ins is the time saving to achieve effects which are within the creative realm of those editors. ...
    (rec.photo.digital)