diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-01-05 11:16:09 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-01-05 11:16:09 +0000 |
commit | 2b08e1491522143e4c75eab46b12b8855309d372 (patch) | |
tree | 5dfa1a4b3acf7ef8b184f14cb81578b03a3c1524 /usr.sbin | |
parent | 001f3c0cbe2aecd8671e8ac6a8e1a13d6de8a48c (diff) |
common pattern, put it there since everything uses Error.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Error.pm | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm index d770ae7f7d1..19cc928e51d 100644 --- a/usr.sbin/pkg_add/OpenBSD/Error.pm +++ b/usr.sbin/pkg_add/OpenBSD/Error.pm @@ -1,7 +1,7 @@ # ex:ts=8 sw=4: -# $OpenBSD: Error.pm,v 1.19 2009/11/15 09:53:52 espie Exp $ +# $OpenBSD: Error.pm,v 1.20 2010/01/05 11:16:08 espie Exp $ # -# Copyright (c) 2004 Marc Espie <espie@openbsd.org> +# Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org> # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -17,6 +17,22 @@ use strict; use warnings; +package OpenBSD::Auto; +sub cache(*&) +{ + my ($sym, $code) = @_; + my $callpkg = caller; + my $actual = sub { + my $self = shift; + if (!defined $self->{$sym}) { + $self->{$sym} = &$code($self); + } + return $self->{$sym}; + }; + no strict 'refs'; + *{$callpkg."::$sym"} = $actual; +} + package OpenBSD::Error; require Exporter; our @ISA=qw(Exporter); |