Scarborough has asked for the wisdom of the Perl Monks concerning the following question:

I have been working ona job schedular for some time and came up with the idea of having a option to store schedule data as XML

However obviously the code part produces an error Can't encode a value of type: CODE at C:\ROBERT\psch\formonks.pm line 45

Anyone approched something like this before below is a small section of code.

use strict; my $inv870 = new Job("INV870","perl INV870.pl","172.**.***.**",sub{ #do +something after the job }); my $suite = new Suite('AMREPS',[$inv870]); print $suite->xml; package Job; sub new { my $class = shift; my $name = shift; my $command = shift; my $location = shift; my $afterhook= shift; my $data = {UNIQUENAME => $name, COMMAND_LINE => $command, LOCATION => $location, HOOK => $afterhook}; my $self = bless $data, $class; return $self; } 1; package Suite; use XML::Simple; sub new { my $class = shift; my $name = shift; my $jobarray = shift; my $data = {UNIQUENAME => $name, JOBS => $jobarray}; my $self = bless $data, $class; return $self; } sub xml{ my $class = shift; return XMLout($class); } 1;

Replies are listed 'Best First'.
Re: XML and code snippets
by holli (Abbot) on Jul 28, 2005 at 13:11 UTC
    Well, you have a code reference in your data structure and obviously XML::Simple cannot dump that. Simple, eh? ;-)

    That is because perl does not store the coderef in source (as text) but in compiled form somewhere in memory. So it can never be dumped. Maybe you want to store the code as text in your structure and eval it where appropriate.


    holli, /regexed monk/
      Sorry not clear, I understood why it didn't work and when I take out the code ref. it works fine. I was wondering if anyone had tried a way to store code in XML! I don't wont to waste lots of time if I'm never going to get anywhere.

      UPDATE. Thanks for the second line I'll give it a try.

Re: XML and code snippets
by jhourcle (Prior) on Jul 28, 2005 at 13:55 UTC

    I've done scheduled events in terms of storing them for display on a calendar.

    Instead of trying to come up with my format for storing the information, I dumped the database out of my palm, and took a look at how they organized things.

    These days, I'd probably use iCal, for which there seem to be a number of modules in CPAN. If you wanted to embed the data in something else, there's also hCalendar. Another common standard for scheduling is the Vixie crontab format, as you look to be scheduling commands to trigger ... and there's modules for that, too. (hell, there's modules for cron, even.)

      Thanks for your help on this one. I'll read up on these modules. They look very interesting.