If you would like a hint of what it would look like as an OO module rather than as an eval'd text file then consider the following:
First a sketch of the plug in base class:
use strict; use warnings; package PluginBase; sub new { my ($class, %params) = @_; return bless {%params}, $class; } sub get_arg { my ($self, $arg) = @_; return $self->{command_args}{$arg}; } sub quote_special { my ($self, $data) = @_; $data =~ s@\[@<lftsqbrk/>@g; $data =~ s@\]@<rtsqbrk/>@g; $data =~ s@\(@<lftbrk/>@g; $data =~ s@\)@<rtbrk/>@g; $data =~ s@\+@<plus/>@g; $data =~ s@\?@<ques/>@g; $data =~ s@\'@<apos/>@g; $data =~ s@\$@<dollar/>@g; return $data; } sub get_raw_data { my $self = shift; return $self->{raw_data}; } sub get_data { my $self = shift; return $self->{data}; } 1;
and then the plug in:
use strict; use warnings; package GetURL; use base 'PluginBase'; sub new { my ($class, %params) = @_; return $class->SUPER::new (%params); } sub doit { my $self = shift; my $module = 'LWP::Simple'; return "<error>Couldnt retrieve url</error>" unless $module->use; my $w_data = $self->get_arg ('url'); return "<error>Couldnt find channel tag</error>" unless $self->get_raw_data () =~ m@<channel>(.*?)</channel>@s; my $channel_data = $self->quote_special ($1); my $result = ''; while ($channel_data =~ m@<item>(.*?)</item>@s) { my $item_info = $1; my $mask = $self->get_data (); #the output mask is set to a copy of the data #handed to the plugin while ($mask =~ m@<d>(.*?)</d>@s) { my $get_item = $1; my $item_string; $item_string = $1 if $item_info =~ m@<$get_item>(.*?)</$ge +t_item>@s; $mask =~ s@<d>$get_item</d>@$item_string@; } $result .= $mask; $channel_data =~ s@<item>$item_info</item>@@; } return $result; }
Note that a lot of guesses are being made about where stuff might come from in the original code. Using an object that becomes pretty clear. There is also a huge benefit when (for example) you decide you need another level of nesting. Make the changes in the base class and all past, current and future plug ins do the right thing (cf. quote_special).
In reply to Re: Modernisation Needed
by GrandFather
in thread Modernisation Needed
by simonodell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |