Namespace discussion: Event::ExecFlow

[email protected] (Jörn Reder) Fri, 30 Dec 2005 16:48:30 +0100
Newsgroups perl.loop
Message-ID <[email protected]>
------------=_1135957710-14425-13
Content-Type: text/plain; charset="iso-8859-15"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

=0A=
Hi,=0A=
=0A=
I'm writing a new module and I'm seeking for a good name for it.=0A=
=0A=
My current choice is=0A=
=0A=
  Event::ExecFlow=0A=
=0A=
and so I'm writing to this list to discuss my plans of namespace=20=0A=
polution ;)=0A=
=0A=
I try to explain what the module does. At first: I factored this module=0A=
out of dvd::rip, a Perl Gtk2 GUI for copying DVD's. It's a frontend for=0A=
transcode and various other video related command line tools. And that's=0A=
where Event::ExecFlow comes into place.=0A=
=0A=
It offers a high level API to declare jobs, which mainly execute=20=0A=
external commands, parse their output to get progress information,=20=0A=
triggers actions when the command has been finished and so on. Such jobs=0A=
can be chained together to fulfill rather complex tasks which consists=20=
=0A=
of a bunch of jobs.=0A=
=0A=
The whole I/O is asynchronous resp. the execution flow is event-driven,=0A=
that's why I think Event::ExecFlow is a proper name. I'm planning to use=0A=
AnyEvent to abstract from specific mainloop implementations (Event, Glib=0A=
etc.).=0A=
=0A=
Just a short SYNOPSIS to see how it works:=0A=
=0A=
  my $job =3D Event::ExecFlow::Job::Group->new (=0A=
    jobs =3D> [=0A=
      Event::ExecFow::Job::Command->new (=0A=
        name            =3D> "transcode",=0A=
        title           =3D> "Transcoding DVD title to OGG",=0A=
        command         =3D> "transcode -i /dev/dvd ...",=0A=
        fetch_output    =3D> 1,=0A=
        progress_max    =3D> 4711, # number of frames=0A=
        progress_parser =3D> sub {=0A=
          my ($job, $buffer) =3D @_;=0A=
          $job->set_progress_cnt($1) if $buffer =3D~ /\[\d+-(\d+)\]/;=0A=
          #-- or simply write this:=0A=
          #--   progress_parser =3D> qr/\[\d+-(\d+)\]/,=0A=
        },=0A=
      ),=0A=
      Event::ExecFow::Job::Code->new (=0A=
        title         =3D> "Do some checks",=0A=
        code          =3D> sub {=0A=
          my ($job) =3D @_;=0A=
          my $transcode =3D $job->get_group->get_job_by_name("transcode");=
=0A=
          if ( $transcode->get_output !~ /.../ ) {=0A=
            $job->set_error_message("XY check failed");=0A=
          }=0A=
          #-- this could be done easier as a post_callback added to=0A=
          #-- the "transcode" job above, but it's nevertheless a good=0A=
          #-- example for the 'Code' job type and shows how jobs can=0A=
          #-- interfere with each other.=0A=
        },=0A=
      ),=0A=
      Event::ExecFow::Job::Command->new (=0A=
        title         =3D> "Muxing OGG file",=0A=
        command       =3D> "ogmmerge ...",=0A=
        no_progress   =3D> 1,=0A=
      ),=0A=
    ],=0A=
  );=0A=
=0A=
  #-- this inherits from Event::ExecFlow::Frontend=0A=
  my $frontend =3D Video::DVDRip::GUI::ExecFlow->new(...);=0A=
  $frontend->start_job($job);=0A=
=0A=
You can recursively define arbitrary complex job structures by putting=20=
=0A=
Groups into Groups. There are some more features like pre- and=20=0A=
post-callbacks which can do additional checks and even manipulate the=20=0A=
job plan at runtime, e.g. depending on the state of previously executed=0A=
jobs. As well Event::ExecFlow offers a unique interface for progress=20=0A=
compution, error handling, warning messages, logging and stuff.=0A=
=0A=
The $frontend object is application specific and must implement the=20=0A=
Event::ExecFlow::Frontend interface (which is pretty small, currently=20=0A=
seven very simple methods). $frontend receives events/method calls to do=0A=
progress updates on the UI. This way you can specify job execution plans=0A=
independently from the UI, which may be implemented using Gtk2, Tk, Qt=20=
=0A=
or a simple text interface or whatever.=0A=
=0A=
Any comments are welcome.=0A=
=0A=
Regards,=0A=
=0A=
Joern=0A=
=0A=
--=20=0A=
LINUX - Linux Is Not gnU linuX=0A=

------------=_1135957710-14425-13
Content-Type: application/pgp-signature
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQBDtVbO2hNi0Chc9HMRA4vhAJ0TfUJnWiS3wWbG6w85xv5Jk8Oy3gCfTM3/
bOqRFUEixmm97AUg4hPxVoQ=
=Rs5x
-----END PGP SIGNATURE-----

------------=_1135957710-14425-13--