diff options
| author | Angelo Naselli <anaselli@linux.it> | 2014-01-06 00:59:45 +0100 | 
|---|---|---|
| committer | Angelo Naselli <anaselli@linux.it> | 2014-01-06 00:59:45 +0100 | 
| commit | 11533544ca01c2c54899af0a00f2c062c1831433 (patch) | |
| tree | cdd13f3a209618ddde3a6927a392590238a01a4c /Module.pm | |
| parent | eb0eab8fc6d0c89262daa80d199bb7091540943b (diff) | |
| download | colin-keep-11533544ca01c2c54899af0a00f2c062c1831433.tar colin-keep-11533544ca01c2c54899af0a00f2c062c1831433.tar.gz colin-keep-11533544ca01c2c54899af0a00f2c062c1831433.tar.bz2 colin-keep-11533544ca01c2c54899af0a00f2c062c1831433.tar.xz colin-keep-11533544ca01c2c54899af0a00f2c062c1831433.zip | |
- Added a Base class for modules.
- Now configuration can be read also int /etc/categories.conf.d/
  so that external modules can add their own configuration to be launched and
  added to admin panel
- perl modules can be run by extending Module class, creating a start()
  method and configuring module entry in categories configuration as class element
- Admin User now extends Module
Diffstat (limited to 'Module.pm')
| -rw-r--r-- | Module.pm | 91 | 
1 files changed, 76 insertions, 15 deletions
| @@ -22,28 +22,77 @@  #Class Module  package Module; +use Moose; + +=head1 VERSION + +Version 0.01 + +=cut + +our $VERSION = '1.0.0'; +  use strict;  use warnings;  use diagnostics;  use yui; -sub new { -    my ($class, $newName, $newIcon, $newLaunch) = @_; -    my $self = { -        my $name = 0, -        my $icon = 0, -        my $launch = 0, -        my $button = 0 -    }; -    bless $self, 'Module'; -     -    $self->{name} = $newName; -    $self->{icon} = $newIcon; -    $self->{launch} = $newLaunch; - -    return $self; +=head1 SUBROUTINES/METHODS + +=head2 create - returns a Module object such as a module +                launcher (this object) or an extension of +                this class + +=cut + +sub create { +    my $class = shift; +    $class = ref $class || $class; +    my (%params) = @_; + +    my $obj; +    if ( exists $params{-CLASS} ) { +        my $driver = $params{-CLASS}; +         +        eval { +            my $pkg = $driver; +            $pkg =~ s/::/\//g; +            $pkg .= '.pm'; +            require $pkg; +            $obj=$driver->new(); +        }; +        if ( $@ ) { +            die "Error getting obj for driver $params{-CLASS}: $@"; +            return undef; +        } +    } +    else { +        $obj = new Module(@_); +    } +    return $obj;  } +has 'icon' => ( +    is      => 'rw', +    isa     => 'Str', +); + +has 'name' => ( +    is      => 'rw', +    isa     => 'Str', +); + +has 'launch' => ( +    is      => 'rw', +    isa     => 'Str', +); + +has 'button' => ( +    is      => 'rw', +   init_arg => undef, +); + +  sub setButton {      my ($self, $button) = @_;      $self->{button} = $button; @@ -55,4 +104,16 @@ sub removeButton {      undef($self->{button});  } +# base class launcher +sub start { +    my $self = shift; + +    my $err = yui::YUI::app()->runInTerminal( $self->{launch} . " --ncurses"); +    if ($err == -1) { +        system($self->{launch}); +    } +} + + +no Moose;  1; | 
