Update of /cvsroot/fink/fink/perlmod/Fink
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19510/perlmod/Fink

Modified Files:
        ChangeLog Engine.pm Finally.pm PkgVersion.pm 
Log Message:
new Finally work

Index: PkgVersion.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/PkgVersion.pm,v
retrieving revision 1.543
retrieving revision 1.544
diff -u -d -r1.543 -r1.544
--- PkgVersion.pm       22 Mar 2006 05:41:20 -0000      1.543
+++ PkgVersion.pm       23 Mar 2006 23:11:43 -0000      1.544
@@ -75,7 +75,12 @@
 
 our %perl_archname_cache;
 
-END { }                                # module clean-up code here (global 
destructor)
+# Hold the trees of packages that we've built, so we can scan them
+our %built_trees;
+
+END {
+       scanpackages();
+}
 
 =head1 NAME
 
@@ -1162,6 +1167,18 @@
        }
 }
 
+=item is_bootstrapping
+
+  my $bool = $pv->is_bootstrapping;
+
+Are we in bootstrap mode?
+
+=cut
+
+sub is_bootstrapping {
+       return $_[0]->{_bootstrap};
+}
+
 =item get_name
 
 =item get_version
@@ -4096,6 +4113,8 @@
                                                        "the directory manually 
to save disk space. ".
                                                        "Continuing with normal 
procedure.");
        }
+       
+       $built_trees{$self->get_full_tree} = 1;
 }
 
 =item phase_activate
@@ -4354,254 +4373,6 @@
        Fink::PkgVersion->dpkg_changed;
 }
 
-# create an exclusive lock for the %f of the parent using dpkg
-sub set_buildlock {
-       my $self = shift;
-
-       # allow over-ride
-       return if Fink::Config::get_option("no_buildlock");
-
-       # lock on parent pkg
-       if ($self->has_parent) {
-               return $self->get_parent->set_buildlock();
-       }
-
-       # bootstrapping occurs before we have package-management tools
-       # needed for buildlocking. If you're bootstrapping into a location
-       # that already has a running fink, you already know you're gonne
-       # hose whatever may be running under that fink...
-       return if $self->{_bootstrap};
-
-       # The plan: get an exlusive lock for %n-%v-%r_$timestamp that
-       # automatically goes away when this fink process quit. Install a
-       # %n-%v-%r package that prohibits removal of itself if that lock
-       # is present.  It's always safe to attempt to remove all installed
-       # buildlock pkgs since they can each determine if these locks are
-       # dead.  Attempting to install a lockpkg for the same %n-%v-%r
-       # will cause existing one to attempt to be removed, which will
-       # fail iff its lock is still alive. Fallback to the newer pkg's
-       # prerm is okay because that will also be blocked by its own live
-       # lock.
-
-       print "Setting runtime build-lock...\n";
-
-       my $lockdir = "$basepath/var/run/fink/buildlock";
-       mkdir_p $lockdir or
-               die "can't create $lockdir directory for buildlocks\n";
-
-       my $timestamp = strftime "%Y.%m.%d-%H.%M.%S", localtime;
-       my $lockfile = $lockdir . '/' . $self->get_fullname() . 
"_$timestamp.lock";
-       my $lock_FH = lock_wait($lockfile, exclusive => 1);
-
-       my $pkgname = $self->get_name();
-       my $pkgvers = $self->get_fullversion();
-       my $lockpkg = 'fink-buildlock-' . $self->get_fullname();
-
-       my $destdir = $self->get_install_directory($lockpkg);
-
-       if (not -d "$destdir/DEBIAN") {
-               mkdir_p "$destdir/DEBIAN" or
-                       die "can't create directory for control files for 
package $lockpkg\n";
-       }
-
-       # generate dpkg "control" file
-
-       my $control = <<EOF;
-Package: $lockpkg
-Source: fink
-Version: $timestamp
-Section: unknown
-Installed-Size: 0
-Architecture: $debarch
-Description: Package compile-time lockfile
- This package represents the compile-time dependencies of a
- package being compiled by fink. The package being compiled is:
-   $pkgname ($pkgvers)
- and the build process begun at $timestamp
- .
- Web site: http://wiki.opendarwin.org/index.php/Fink:buildlocks
- .
- Maintainer: Fink Core Group <[EMAIL PROTECTED]>
-Maintainer: Fink Core Group <[EMAIL PROTECTED]>
-Provides: fink-buildlock
-EOF
-
-       # buildtime (anti)dependencies of pkg are runtime (anti)dependencies of 
lockpkg
-       my $depfield;
-       $depfield = &lol2pkglist($self->get_depends(1, 1));
-       if (length $depfield) {
-               $control .= "Conflicts: $depfield\n";
-       }
-       $depfield = &lol2pkglist($self->get_depends(1, 0));
-       if (length $depfield) {
-               $control .= "Depends: $depfield\n";
-       }
-
-       ### write "control" file
-       if (open my $controlfh, '>', "$destdir/DEBIAN/control") {
-               print $controlfh $control;
-               close $controlfh or die "can't write control file for $lockpkg: 
$!\n";
-       } else {
-               die "can't write control file for $lockpkg: $!\n";
-       }
-
-       ### set up the lockfile interlocking
-
-       # this is implemented in perl but PreRm is in bash so we gonna in-line 
it
-       my $prerm = <<EOF;
-#!/bin/bash -e
-
-if [ failed-upgrade = "\$1" ]; then
-  exit 1
-fi
-
-if perl -e 'exit 0 unless eval { require Fink::PkgVersion }; \\
-       exit 0 unless defined &Fink::PkgVersion::can_remove_buildlock; \\
-       exit !Fink::PkgVersion->can_remove_buildlock("$lockfile")'; then
-  rm -f $lockfile
-  exit 0
-else
-  cat <<EOMSG
-There is currently an active buildlock for the package
-     $pkgname ($pkgvers)
-meaning some other fink process is currently building it.
-EOMSG
-  exit 1
-fi
-EOF
-
-       ### write prerm file
-       if (open my $prermfh, '>', "$destdir/DEBIAN/prerm") {
-               print $prermfh $prerm;
-               close $prermfh or die "can't write PreRm file for $lockpkg: 
$!\n";
-               chmod 0755, "$destdir/DEBIAN/prerm";
-       } else {
-               die "can't write PreRm file for $lockpkg: $!\n";
-       }
-
-       ### store our PID in a file in the buildlock package
-       my $deb_piddir = "$destdir$lockdir";
-       if (not -d $deb_piddir) {
-               mkdir_p $deb_piddir or
-                       die "can't create directory for lockfile for package 
$lockpkg\n";
-       }
-       if (open my $lockfh, ">$deb_piddir/" . $self->get_fullname() . ".pid") {
-               print $lockfh $$,"\n";
-               close $lockfh or die "can't create pid file for package 
$lockpkg: $!\n";
-       } else {
-               die "can't create pid file for package $lockpkg: $!\n";
-       }
-
-       ### create .deb using dpkg-deb (in buildpath so apt doesn't see it)
-       if (&execute("dpkg-deb -b $destdir $buildpath")) {
-               die "can't create package $lockpkg\n";
-       }
-       rm_rf $destdir or
-               &print_breaking("WARNING: Can't remove package root directory ".
-                                               "$destdir. ".
-                                               "This is not fatal, but you may 
want to remove ".
-                                               "the directory manually to save 
disk space. ".
-                                               "Continuing with normal 
procedure.");
-
-       # install lockpkg (== set dpkg lock on our deps)
-       print "Installing build-lock package...\n";
-       my $debfile = 
$buildpath.'/'.$lockpkg.'_'.$timestamp.'_'.$debarch.'.deb';
-       my $lock_failed = &execute(dpkg_lockwait() . " -i $debfile", 
ignore_INT=>1);
-       Fink::PkgVersion->dpkg_changed;
-
-       if ($lock_failed) {
-               print_breaking rejoin_text <<EOMSG;
-Can't set build lock for $pkgname ($pkgvers)
-
-If any of the above dpkg error messages mention conflicting packages or
-missing dependencies -- for example, telling you that the package
-fink-buildlock-$pkgname-$pkgvers
-conflicts with something else -- fink has probably gotten confused by trying 
-to build many packages at once. Try building just this current package
-$pkgname (i.e, "fink build $pkgname"). When that has completed successfully, 
-you could retry whatever you did that led to the present error.
-
-Regardless of the cause of the lock failure, don't worry: you have not
-wasted compiling time! Packages that had been completely built before
-this error occurred will not have to be recompiled.
-
-See http://wiki.opendarwin.org/index.php/Fink:buildlocks for more information.
-EOMSG
-
-               # Failure due to dependency problems leaves lockpkg in an
-               # "unpacked" state, so try to remove it entirely.
-               unlink $lockfile;
-               close $lock_FH;
-               &execute(dpkg_lockwait() . " -r $lockpkg >/dev/null", 
ignore_INT=>1);
-       }
-
-       # Even if installation fails, no reason to keep this around
-       rm_f $debfile or
-               &print_breaking("WARNING: Can't remove binary package file ".
-                                               "$debfile. ".
-                                               "This is not fatal, but you may 
want to remove ".
-                                               "the file manually to save disk 
space. ".
-                                               "Continuing with normal 
procedure.");
-
-       die "buildlock failure\n" if $lock_failed;
-
-       # record buildlock package name so we can remove it during 
clear_buildlock
-       $self->{_buildlock} = {
-               lockfile => $lockfile,
-               lock_FH  => $lock_FH,
-               lockpkg  => $lockpkg,
-               finalizer => Fink::Finally->new(sub { 
$self->_real_clear_buildlock }),
-       };
-}
-
-# external wrapper for _real_clear_buildlock
-sub clear_buildlock {
-       my ($self) = @_;
-       
-       # lock on parent pkg
-       if ($self->has_parent) {
-               return $self->get_parent->clear_buildlock();
-       }
-       return unless $self->{_buildlock};
-       
-       $self->{_buildlock}->{finalizer}->run;
-       
-       # This should be a good time to scan the packages
-       my $autoscan = !$config->has_param("AutoScanpackages")
-               || $config->param_boolean("AutoScanpackages");
-       if ($autoscan && apt_available) {
-               require Fink::Engine;
-               Fink::Engine::scanpackages(1, $self->get_full_tree);
-               Fink::Engine::finalize('apt-get update', sub {
-                       Fink::Engine::aptget_update();
-               });
-       }
-}
-
-# remove the lock created by set_buildlock
-sub _real_clear_buildlock {
-       my $self = shift;
-
-       # we were locked...
-       print "Removing runtime build-lock...\n";
-       close $self->{_buildlock}->{lock_FH};
-
-       print "Removing build-lock package...\n";
-       my $lockpkg = $self->{_buildlock}->{lockpkg};
-
-       # lockpkg's prerm deletes the lockfile
-       if (&execute(dpkg_lockwait() . " -r $lockpkg", ignore_INT=>1)) {
-               &print_breaking("WARNING: Can't remove package ".
-                                               "$lockpkg. ".
-                                               "This is not fatal, but you may 
want to remove ".
-                                               "the package manually as it may 
interfere with ".
-                                               "further fink operations. ".
-                                               "Continuing with normal 
procedure.");
-       }
-       Fink::PkgVersion->dpkg_changed;
-       delete $self->{_buildlock};
-}
-
 =item ensure_gpp_prefix
 
   my $prefix_path = ensure_gpp_prefix $gpp_version;
@@ -5223,20 +4994,6 @@
        return $return;
 }
 
-=item can_remove_buildlock
-
-  my $fh = Fink::PkgVersion->can_remove_buildlock($lockfile);
-
-Test if it is safe to remove a buildlock. After calling this, either the $fh
-should be closed, or the lockfile deleted.
-
-=cut
-
-sub can_remove_buildlock {
-       my ($class, $lockfile) = @_;
-       return lock_wait("$lockfile", exclusive => 1, no_block => 1);
-}
-
 =item get_full_trees
 
   my @trees = $pv->get_full_trees;
@@ -5260,6 +5017,29 @@
        return ($_[0]->get_full_trees)[-1];
 }
 
+=item scanpackages
+
+  scanpackages;
+
+Scan the packages for the packages we built this run.
+
+=cut
+
+sub scanpackages {
+       # Scan packages in the built trees, if that's desired
+       if (%built_trees) {
+               my $autoscan = !$config->has_param("AutoScanpackages")
+                       || $config->param_boolean("AutoScanpackages");
+               
+               if ($autoscan && apt_available) {
+                       require Fink::Engine; # yuck
+                       Fink::Engine::scanpackages(0, keys %built_trees);
+                       Fink::Engine::aptget_update();
+               }
+               %built_trees = ();
+       }
+}
+
 =back
 
 =cut

Index: Engine.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/Engine.pm,v
retrieving revision 1.365
retrieving revision 1.366
diff -u -d -r1.365 -r1.366
--- Engine.pm   22 Mar 2006 20:43:27 -0000      1.365
+++ Engine.pm   23 Mar 2006 23:11:42 -0000      1.366
@@ -35,6 +35,8 @@
                                 &get_term_width &die_breaking);
 use Fink::Configure qw(&spotlight_warning);
 use Fink::Finally;
+use Fink::Finally::Buildlock;
+use Fink::Finally::BuildConflicts;
 use Fink::Package;
 use Fink::PkgVersion;
 use Fink::Config qw($config $basepath $debarch $dbpath);
@@ -124,13 +126,11 @@
          'show-deps'         => [\&cmd_show_deps,         1, 0, 0],
        );
 
-# Groups of finalizers for &process 
-our @finalizers = ({ });
-
 END { }                                # module clean-up code here (global 
destructor)
 
 ### constructor using configuration
 
+# Why is this here? Why not just inherit from Fink::Base?
 sub new_with_config {
        my $proto = shift;
        my $class = ref($proto) || $proto;
@@ -163,6 +163,7 @@
 
 sub process {
        my $self = shift;
+       
        my $orig_ARGV = shift;
        my $cmd = shift;
        my @args = @_;
@@ -187,8 +188,6 @@
                my @argv_stack = @{Fink::Config::get_option('_ARGV_stack', [])};
                push @argv_stack, [ @$orig_ARGV ];
                Fink::Config::set_options({ '_ARGV_stack' => [EMAIL PROTECTED] 
});
-               
-               push @finalizers, { }; # new finalizer group
        }
 
        ($proc, $pkgflag, $rootflag, $aptgetflag) = @{$commands{$cmd}};
@@ -264,6 +263,9 @@
        my $proc_rc = { '$@' => $@, '$?' => $? };  # save for later
        my $retval = 0;
        
+       # Scan packages before we print any error message
+       Fink::PkgVersion::scanpackages();
+       
        # Rebuild the command line, for user viewing
        my $commandline = join ' ', 'fink', @$orig_ARGV;
        my $notifier = Fink::Notify->new();
@@ -293,8 +295,6 @@
                my @argv_stack = @{Fink::Config::get_option('_ARGV_stack', [])};
                pop @argv_stack;
                Fink::Config::set_options({ '_ARGV_stack' => [EMAIL PROTECTED] 
});
-               
-               pop @finalizers; # run current finalizer group
        }
 
        return $retval;;
@@ -622,24 +622,6 @@
        }
 }
 
-=item finalize
-
-  finalize $name, $code;
-
-Add some code that should run when I<&process> finishes. Only the first 
I<$code>
-for a given I<$name> is run, all later calls are ignored.
-
-Supports re-entrancy.
-
-=cut
-
-sub finalize {
-       my ($name, $code) = @_;
-       my $group = $finalizers[-1];
-       return if exists $group->{$name};
-       $group->{$name} = Fink::Finally->new($code);
-}
-
 =item aptget_update
 
   my $success = aptget_update $quiet;
@@ -1837,21 +1819,22 @@
                                        ### installed in an other loop
                                        if (!$package->is_installed() || $op == 
$OP_REBUILD) {
                                                # Remove the BuildConflicts, 
and reinstall after
-                                               my $fin = 
remove_buildconflicts($conflicts{$pkgname});
+                                               my $buildconfs = 
Fink::Finally::BuildConflicts->new(
+                                                       $conflicts{$pkgname});
                                                
                                                $package->log_output(1);
-                                               $package->set_buildlock();
-                                               $package->phase_unpack();
-                                               $package->phase_patch();
-                                               $package->phase_compile();
-                                               $package->phase_install();
-                                               $package->phase_build();
-                                               $package->clear_buildlock();
+                                               {
+                                                       my $bl = 
Fink::Finally::Buildlock->new($package);
+                                                       
$package->phase_unpack();
+                                                       $package->phase_patch();
+                                                       
$package->phase_compile();
+                                                       
$package->phase_install();
+                                                       $package->phase_build();
+                                               }
                                                $package->log_output(0);
-                                               
-                                               $fin->run;
                                        } else {
-                                               &real_install($OP_BUILD, 0, 1, 
$dryrun, $package->get_name());
+                                               &real_install($OP_BUILD, 0, 1, 
$dryrun,
+                                                       $package->get_name());
                                        }
                                }
                        }
@@ -2749,7 +2732,7 @@
 
 =item list_removals
 
-  my @pkgnames = list_removals \%deps, \%conflicts;
+  my @pkgnames = $engine->list_removals \%deps, \%conflicts;
 
 List the package names that we may remove at some point.
 
@@ -2771,43 +2754,6 @@
        return sort keys %removals;
 }
 
-=item remove_buildconflicts
-
-  my $finally = remove_buildconflicts @pvs;
-
-Remove the BuildConflicts of a package, and return a Fink::Finally cleanup
-task that can restore them.
-
-=cut
-
-sub remove_buildconflicts {
-       my ($pvs) = @_;
-       
-       my @must_remove = grep { $_->is_installed } @$pvs;
-       my @cant_restore = grep { !$_->is_present } @must_remove;
-       
-       if ([EMAIL PROTECTED]) {
-               return Fink::Finally->new(sub { }); # Do nothing
-       } elsif (@cant_restore) {
-               die_breaking "The following packages must be temporarily 
removed, but "
-                       . "there are no .debs to restore them from:\n  "
-                       . join(' ', sort map { $_->get_name } @cant_restore);
-       } else {
-               my @names = sort map { $_->get_name } @must_remove;
-               my $names = join(' ', @names);
-               my $recover = sub {
-                       print_breaking_stderr "Restoring removed 
BuildConflicts:\n "
-                               . " $names";
-                       Fink::PkgVersion::phase_activate([EMAIL PROTECTED]);
-               };
-               
-               print_breaking_stderr "Temporarily removing BuildConflicts:\n 
$names";
-               Fink::PkgVersion::phase_deactivate([EMAIL PROTECTED]);
-               
-               return Fink::Finally->new($recover);
-       }
-}
-
 =back
 
 =cut

Index: Finally.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/Finally.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Finally.pm  22 Mar 2006 22:46:53 -0000      1.3
+++ Finally.pm  23 Mar 2006 23:11:43 -0000      1.4
@@ -28,92 +28,195 @@
 
 =head1 NAME
 
-Fink::Finally - Run cleanup code unconditionally.
+Fink::Finally - An object that can be cleaned up safely.
 
 =head1 DESCRIPTION
 
-Usually cleanup code runs explicitly, but sometimes exceptions can cause it
-to be bypassed. Fink::Finally allows such code to be executed even if an
-exception occurs.
+Often an object wishes to release resources when it is destroyed. However,
+Perl's DESTROY has some problems which make it inappropriate to be used
+directly.
+
+A Fink::Finally object will not run in a fork (causing two runs). It will also
+not run twice in normal circustances. Finally, it ensures that $@ and $? are
+not changed.
+
+Circular references should never include a Fink::Finally object. This will 
cause
+the object to clean up only during global destruction, when it cannot depend
+on any references to exist.
 
 =head1 SYNOPSIS
 
-  use Fink::Finally;
+  package Fink::Finally::Subclass;
+  use base 'Fink::Finally';
+  sub initialize       { ... }
+  sub finalize         { ... }
 
-  # $fin runs even if an exception is thrown
-  my $fin = Fink::Finally->new(sub { ... });
+  package main;
 
-  function_which_might_die();
+  # Explicit cleanup
+  my $explicit = Fink::Finally::Subclass->new(@args);
+  $explicit->cleanup;
 
-  $fin->run;
+  # Implicit cleanup
+  {
+      my $implicit = Fink::Finally::Subclass->new(@args);
+      # automatically cleaned up when it goes out of scope
+  }
 
-=head1 METHODS
+  # Preventing cleanup
+  {
+      my $prevent = Fink::Finally::Subclass->new(@args);
+      $prevent->cancel_cleanup;
+      # will not be cleaned up
+  }
+
+=cut
+
+# Key to private storage
+my $PRIV = "__" . __PACKAGE__;
+
+=head1 EXTERNAL INTERFACE
 
 =over 4
 
 =item new
 
-  my $fin = Fink::Finally->new(sub { ... });
+  my $finally = Fink::Finally::Subclass->new(...);
 
-Create a finalizer to run the given cleanup code.
+Construct an object which will clean up when it goes out of scope.
 
-The code will run either when C<$finally->run> is called, or when I<$fin> goes
-out of scope. The return value of the code is not accessible, since the caller
-may not get a chance to explictly call I<&run>.
+=item cleanup
+
+  $finally->cleanup;
+
+Explicitly cause this object to clean up. Clean up will not happen again when
+the object leaves scope.
+
+This method should rarely be overridden, subclasses are encouraged to
+override I<&finalize> instead.
 
 =cut
 
-sub initialize {
-       my ($self, $code) = @_;
-       $self->SUPER::initialize;
+sub cleanup {
+       my ($self) = @_;
+       return 0 unless $self->{$PRIV}->{primed};               # Don't run 
twice
+       return 0 if $self->{$PRIV}->{cancelled};                # Don't run if 
cancelled
+       return 0 unless $self->{$PRIV}->{pid} == $$;    # Don't run in a fork
        
-       die "A Finally needs some code to run!\n"
-               unless defined $code && ref($code) eq 'CODE';
-       $self->{_code} = $code;
-       $self->{_pid} = $$;
-       $self->{_primed} = 1; # ready to go
+       local ($@, $?); # Preserve variables
+       $self->{$PRIV}->{primed} = 0; # Don't run again
+       $self->finalize();
+       return 1;
 }
 
-=item run
+sub DESTROY {
+       $_[0]->cleanup;
+}
 
-  $fin->run;
+=item cancel_cleanup
 
-Explicitly run the cleanup code in this finalizer.
+  $finally->cancel_cleanup;
 
-If called multiple times, only the first will actually do anything.
+Prevent this object from cleaning up.
 
 =cut
 
-sub run {
+sub cancel_cleanup {
+       $_[0]->{$PRIV}->{cancelled} = 1;
+}
+
+=back
+
+=head1 SUBCLASSING
+
+These methods should generally not be called externally, but are useful for
+subclasses to override the functionality of Fink::Finally.
+
+=over 4
+
+=item initialize
+
+  sub initialize {
+      my ($self) = @_;
+      ...
+
+      $self->SUPER::initialize();
+  }
+
+The Fink::Base initializer, automatically called when an object is created
+with I<&new>.
+
+Subclasses are encouraged to override this method, but they B<must> call
+C<$self->SUPER::initialize()> if they intend cleanup to work. It may be
+useful to call I<SUPER::initialize> at the end of I<initialize>, to ensure
+that cleanup only occurs after setup.
+
+=cut
+
+sub initialize {
        my ($self) = @_;
-       delete $self->{_primed}
-               if $self->{_primed} && $$ != $self->{_pid}; # Don't run in forks
-       return unless $self->{_primed};
-       
-       # Preserve exit status
-       my $status = $?;
-       
-       &{$self->{_code}}();
-       delete $self->{_primed};
+       $self->SUPER::initialize();
        
-       $? = $status;
+       $self->{$PRIV}->{primed} = 1;
+       $self->{$PRIV}->{pid} = $$;
 }
 
-sub DESTROY {
-       $_[0]->run;
+=item finalize
+
+  sub finalize {
+      my ($self) = @_;
+      $self->SUPER::finalize();
+
+      ...
+  }
+
+The finalizer that performs the actual cleanup.
+
+Subclasses should almost always override this method. The methods I<&cleanup>
+and I<DESTROY> should rarely be overridden instead, overriding them may make
+cleanup unsafe.
+
+=cut
+
+sub finalize {
+       # Do nothing by default
 }
 
-=item cancel
+=back
 
-  $fin->cancel;
+=head1 SIMPLE CLEANUP
 
-Do not allow this finalizer to run.
+A subclass Fink::Finally::Simple is provided to make safe cleanup available
+when a subclass is overkill.
+
+=over 4
+
+=item new
+
+  my $finally = Fink::Finally::Simple->new($code);
+
+Create a new simple cleanup object.
+
+The code-ref I<$code> will be called to clean up. It will be provided with
+a ref to this object as its only argument.
 
 =cut
 
-sub cancel {
+package Fink::Finally::Simple;
+use base 'Fink::Finally';
+
+sub initialize {
+       my ($self, $code) = @_;
+       die "Fink::Finally::Simple initializer requires a code-ref\n"
+               unless ref($code) && ref($code) eq 'CODE';
+       
+       $self->{_code} = $code;
+       $self->SUPER::initialize();
+}
+
+sub finalize {
        my ($self) = @_;
-       delete $self->{_primed};
+       $self->{_code}->($self);
 }
 
 =back

Index: ChangeLog
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v
retrieving revision 1.1298
retrieving revision 1.1299
diff -u -d -r1.1298 -r1.1299
--- ChangeLog   23 Mar 2006 03:52:47 -0000      1.1298
+++ ChangeLog   23 Mar 2006 23:11:39 -0000      1.1299
@@ -1,3 +1,14 @@
+2006-03-23  Dave Vasilevsky  <[EMAIL PROTECTED]>
+
+       * Finally.pm: Use a pretty OO interface.
+       * Finally/BuildConflicts.pm: New module for BuildConflicts removal and
+       restoration.
+       * Finally/Buildlock.pm: New module for buildlock setting and clearing.
+       * Engine.pm: Remove add_finalizer interface, move BuildConflicts removal
+       to Finally/BuildConflicts.pm 
+       * PkgVersion.pm: Add method is_bootstrapping, move buildlock stuff to
+       Finally/Buildlock.pm. New scapackages stuff in END.
+
 2006-03-22  Dave Vasilevsky  <[EMAIL PROTECTED]>
 
        * CLI.pm: Add logging to &capture, fix open-modes problem. 



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Fink-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fink-commits

Reply via email to