constant-defer-5/0002755000175000017500000000000011525332620011711 5ustar ggggconstant-defer-5/devel/0002755000175000017500000000000011525332617013016 5ustar ggggconstant-defer-5/devel/MyConstantDeferExport.pm0000644000175000017500000000177311415713324017625 0ustar gggg# Copyright 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . package MyConstantDeferExport; use base 'Exporter'; our @EXPORT_OK = ('my_ctime'); use constant::defer my_ctime => sub { print "my_ctime runs\n"; require POSIX; return POSIX::ctime(time()); }; 1; __END__ constant-defer-5/devel/junk/0002755000175000017500000000000011525332617013765 5ustar ggggconstant-defer-5/devel/junk/Attribute-MemoizeToConstant.pm0000644000175000017500000000776011356526020021711 0ustar gggg# no good because Attribute::Handlers doesn't run at the right phase in a # require or eval # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . package Attribute::MemoizeToConstant; use Attribute::Handlers; ## no critic (RequireUseStrict RequireUseWarnings) no strict; no warnings; push @UNIVERSAL::ISA, __PACKAGE__; use constant DEBUG => 0; our $c; my @pending; my $checked = 0; sub MODIFY_CODE_ATTRIBUTES { my ($package, $coderef, @attrs) = @_; if (DEBUG) { print "MemoizeToConstant pending $package $coderef\n"; } push @pending, [$package, $coderef]; if ($checked) { run_pending(); } return grep {$_ ne 'MemoizeToConstant'} @attrs; } CHECK { if (DEBUG) { print "MemoizeToConstant CHECK\n"; } $checked = 1; run_pending(); } sub run_pending { while (@pending) { my ($package, $oldcode) = @{pop @pending}; if (DEBUG) { print " $package $oldcode\n"; } $c = $oldcode; require Scalar::Util; Scalar::Util::weaken ($c); my $found; my $phash = \%{"${package}::"}; foreach my $name (keys %$phash) { my $glob = $phash->{$name}; ref(\$glob) eq 'GLOB' or next; (*{$glob}{CODE} || 0) == $oldcode or next; my $fullname = "${package}::$name"; if (DEBUG) { print " install to $fullname\n"; } *$fullname = sub () { my $value = $oldcode->(@_); *$fullname = sub () { $value }; return $value; }; $found = 1; } $found or warn "MemoizeToConstant func $oldcode not found in $package"; } } 1; __END__ # sub make_func { # return sub () { # my $value = $_[0]oldcode->(@_); # *$sym = sub () { $value }; # return $value; # } # } # use Data::Dumper; # print Dumper(\@_); # # use Data::Dump; # print Data::Dump::dump(\*main::foo); # # my $x = findsym ($package, $coderef); # print "findsym ",Dumper($x); # # no strict; # # my $type = ref($coderef); # Attribute::Handlers holds onto to the original coderef, so it's not freed # when the func is turned into a constant ... package Attribute::MemoizeToConstant; use Attribute::Handlers; use strict; use warnings; our $VERSION = 1; use constant DEBUG => 0; our $c; sub UNIVERSAL::MemoizeToConstant : ATTR(CODE) { my ($package, $typeglob, $oldcode) = @_; $c = $oldcode; Scalar::Util::weaken ($c); if (DEBUG) { print "MemoizeToConstant on '$package' '", *{$typeglob}{NAME}, "' ", $oldcode,"\n"; } no warnings; *$typeglob = sub () { my $value = $oldcode->(@_); *$typeglob = sub () { $value }; return $value; }; } 1; __END__ =head1 NAME Attribute::MemoizeToConstant -- memoize functions to become constants =head1 SYNOPSIS use Attribute::MemoizeToConstant; sub myfunc : MemoizeToConstant { # some long calculation return $x; } =head1 BUGS! Doesn't work when used in a module or file which is loaded by C, C, etc, only from the main program and things brought in C. =head1 DESCRIPTION Attribute C arranges for a function to be memoized so its first call runs the code but it's then transformed into a constant sub (like C) with that first return value. =head1 SEE ALSO =for comment Actually it wants to be attributes(3perl) to avoid attributes(3ncurses), but the formatters complain about that ... L, L, L, L, L =cut constant-defer-5/devel/circular.pl0000644000175000017500000000264711424406742015165 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use warnings; { use constant::defer foo => sub { print "foo runs\n"; 123 }; my $x = \&foo; { no warnings 'redefine'; *foo = sub () { print "new foo runs\n"; 456 }; } require Scalar::Util; print "func ",$x//'undef',"\n"; Scalar::Util::weaken ($x); print "func ",$x//'undef',"\n"; my $y = $constant::defer::DEBUG_LAST_RUNNER; undef $constant::defer::DEBUG_LAST_RUNNER; print "runner ",($y//'undef'),"\n"; Scalar::Util::weaken ($y); print "runner ",($y//'undef'),"\n"; # if (defined $y) { # print "y value ",$y->(),"\n"; # print "runner ",($y//'undef'),"\n"; # } if (defined $y) { require Devel::FindRef; print Devel::FindRef::track($y); } exit 0; } constant-defer-5/devel/package-constants.pl0000644000175000017500000000217211445067766016773 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use warnings; use Package::Constants; use Smart::Comments; { package Foo; use constant PLAIN => 123; use constant::defer HELLO => sub { 123 }; sub SUBR { 123 } sub SUBRPROT () { 123 } sub SUBRPRINT () { print "hello" } use constant::lexical LEX => 123; BEGIN { my @const = Package::Constants->list('Foo'); ### @const } } my @const = Package::Constants->list('Foo'); ### @const constant-defer-5/devel/import.pl0000644000175000017500000000271411424406742014666 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use warnings; use Data::Dumper; use Scalar::Util; use FindBin; use lib::abs $FindBin::Bin; use MyConstantDeferExport ('my_ctime'); { my $orig = \&my_ctime; my $orig_m = \&MyConstantDeferExport::my_ctime; print my_ctime(),"\n"; print MyConstantDeferExport::my_ctime(),"\n"; my $const = \&my_ctime; my $const_m = \&MyConstantDeferExport::my_ctime; print "orig $orig\n"; print "orig_m $orig_m\n"; print "const $const\n"; print "const_m $const_m\n"; if (defined $constant::defer::DEBUG_LAST_SUBR) { print "subr ",$constant::defer::DEBUG_LAST_SUBR//'undef',"\n"; Scalar::Util::weaken($constant::defer::DEBUG_LAST_SUBR); print "subr ",$constant::defer::DEBUG_LAST_SUBR//'undef',"\n"; } exit 0; } constant-defer-5/devel/Memoize/0002755000175000017500000000000011525332617014423 5ustar ggggconstant-defer-5/devel/Memoize/ToConstant.pm0000644000175000017500000001220711256277661017065 0ustar gggg# This was an idea to post-facto mangle a function to be run-once. # # Giving a name an anon-sub to constant::defer seems easier than making a # named sub and then repeating the name to Memoize::ToConstant. # # (The _run() here is old, it doesn't make the first installed sub become # the constant as well as the replacement ...) # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . package Memoize::ToConstant; use 5.006; use strict; use warnings; use Carp; our $VERSION = 1; # an alias for prammatic use ? # *memoize_to_constant = \&import; sub import { my $caller_package = caller; shift @_; # classname foreach my $arg (@_) { my ($fullname, $package, $basename); if ($arg =~ /(.*)::(.*)/s) { $fullname = $arg; $package = $1; $basename = $2; } else { $package = $caller_package; $basename = $arg; $fullname = "${caller_package}::$arg"; } # can() might let a strange package autoload the given func, though # that'd be pretty unusual my $old = $package->can($basename) || croak "Function $fullname not defined"; # print "ToConstant $arg -- $fullname $package $basename $old\n"; no warnings; no strict 'refs'; *$fullname = sub () { _run($fullname,$old,@_) }; } } sub _run { my $fullname = shift; my $old = shift; # print "ToConstant $fullname $old\n"; my @ret = $old->(@_); no warnings; # no strict 'refs'; if (@ret == 0) { *$fullname = \&_nothing; return; } if (@ret == 1) { # constant.pm has an optimization to make a constant by storing a scalar # into the %Foo::Bar:: hash if there's no typeglob for the name yet. # But that doesn't apply here, there's always a typeglob having wrapped # and converted an existing function. # my $value = $ret[0]; *$fullname = sub () { $value }; return $value; } *$fullname = sub () { @ret }; @ret; } sub _nothing () { } 1; __END__ =head1 NAME Memoize::ToConstant -- memoize functions to become constants =head1 SYNOPSIS sub foo { ... }; use Memoize::ToConstant 'foo'; sub bar { ... }; # or a set of functions at once sub quux { ... }; use Memoize::ToConstant 'bar','quux'; use Memoize::ToConstant 'Some::Other::func'; =head1 DESCRIPTION C modifies given functions so the first call runs normally but then becomes a constant sub like C. The effect is an on-demand calculation of a constant, or once-only run of some code. The same sort of thing can be done with the main C module (see L), but ToConstant doesn't have to keep track of different sets of arguments (there's no arguments) and in particular it can discard the original code after it runs, freeing some memory. =head1 MULTIPLE VALUES For consistency the original function is always run in array context, no matter how the memoized wrapper is called. The kind of constant sub the function becomes then depends on the number of values returned. =over 4 =item * For no values the new sub is an empty C. =item * For one value the new sub is a scalar return C. This is the usual case and can be inlined by subsequently loaded code (ie. code loaded after the first run). =item * For two or more values the new sub is an array return C. This is similar to what C gives and in array context (which is presumably the purpose of multiple values) it returns those multiple results. The only subtle thing to note is that when used in scalar context it means the size of the array, ie. how many values. This happens even if your original function was a list style C which in scalar context would normally mean last value in that list. =back =head1 FUNCTIONS There are no functions as such, everything is accomplished through the C import. =over 4 =item C<< use Memoize::ToConstant 'func' >> =item C<< use Memoize::ToConstant 'Some::Package::func' >> Modify the given C to become a constant after the first call to it. An unqualified name is taken to be in the caller package doing the C. That's the normal case, but a fully qualified name (anything with a C<::>) can be given. In either case the function must be defined before ToConstant is applied, sub foo { ... }; use Memoize::ToConstant 'foo'; # right use Memoize::ToConstant 'bar'; # WRONG! sub bar { ... }; =back =head1 SEE ALSO L, L, L, L, L, L, L, L =cut constant-defer-5/devel/Memoize/t-memoize-toconst-2.pl0000644000175000017500000000201111256235500020476 0ustar gggg#!/usr/bin/perl # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use warnings; use Data::Dumper; sub foo { print "foo runs\n"; return (123, 456); } my $got = foo(); print "got $got\n"; print "\n"; sub bar { print "bar runs\n"; return (123, 456); } use Memoize::ToConstant 'bar'; $got = bar(); print "got $got\n"; $got = bar(); print "got $got\n"; exit 0; constant-defer-5/devel/Memoize/ToConstant.t0000644000175000017500000000670011256235441016703 0ustar gggg#!/usr/bin/perl # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use warnings; use Memoize::ToConstant; use Test::More tests => 22; SKIP: { eval 'use Test::NoWarnings; 1' or skip 'Test::NoWarnings not available', 1; } my $want_version = 1; ok ($Memoize::ToConstant::VERSION >= $want_version, 'VERSION variable'); ok (Memoize::ToConstant->VERSION >= $want_version, 'VERSION class method'); Memoize::ToConstant->VERSION ($want_version); # basic use { my $foo_runs = 0; sub foo { $foo_runs = 1; return 123 } my $orig_code; BEGIN { $orig_code = \&foo; } use Memoize::ToConstant 'foo'; is (foo(), 123, 'foo() first run'); is ($foo_runs, 1, 'foo() first runs code'); require Scalar::Util; Scalar::Util::weaken ($orig_code); is ($orig_code, undef, 'orig foo() code garbage collected'); $foo_runs = 0; is (foo(), 123, 'foo() second run'); is ($foo_runs, 0, 'foo() second doesn\'t run code'); } { my $succeeds = (eval { Memoize::ToConstant->import('nosuchfunc') } ? 1 : 0); is ($succeeds, 0, 'no such func provokes die'); } { my $succeeds = 0; BEGIN { ##no critic (BuiltinFunctions::ProhibitStringyEval) if (eval "use Memoize::ToConstant 'before'; 1") { $succeeds = 1; } } sub before { return 789 } is ($succeeds, 0, 'memoize before defined provokes die'); } { my $runs = 0; sub Some::Non::Package::Place::func { $runs = 1; return 'xyz' } use Memoize::ToConstant 'Some::Non::Package::Place::func'; is (Some::Non::Package::Place::func(), 'xyz', 'explicit package first run'); is ($runs, 1, 'explicit package first run runs code'); $runs = 0; is (Some::Non::Package::Place::func(), 'xyz', 'explicit package second run'); is ($runs, 0, 'explicit package second run doesn\'t run code'); } { my $runs = 0; sub three { $runs = 1; return ('a','b','c') } use Memoize::ToConstant 'three'; is_deeply ([ three() ], [ 'a', 'b', 'c' ], 'three return values first run'); is ($runs, 1, 'three return values first run runs code'); $runs = 0; is_deeply ([ three() ], [ 'a', 'b', 'c' ], 'three return values second run'); is ($runs, 0, 'three return values second run doesn\'t run code'); } { my $runs = 0; sub three_scalar { $runs = 1; return ('a','b','c') } use Memoize::ToConstant 'three_scalar'; my $got = three_scalar(); is ($got, 3, 'three values in scalar context return values first run'); is ($runs, 1, 'three values in scalar context return values first run runs code'); $runs = 0; $got = three_scalar(); is ($got, 3, 'three values in scalar context return values second run'); is ($runs, 0, 'three values in scalar context return values second run doesn\'t run code'); } exit 0; constant-defer-5/devel/Memoize/t-memoize-toconst.pl0000644000175000017500000000411311256235474020356 0ustar gggg#!/usr/bin/perl # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use warnings; use Data::Dumper; # my $symtab = do { no strict 'refs'; # \%{"${package}::"} }; BEGIN { my $symtab = \%main::; my $basename = 'foo'; print "symtab ",$symtab->{$basename},"\n"; } sub foo { print "foo\n"; return (123, 456); } BEGIN { my $symtab = \%main::; my $basename = 'foo'; print "symtab ",$symtab->{$basename},"\n"; } print "prototype: '",prototype(\&foo)//'undef',"'\n"; print Dumper (\&foo); use Memoize::ToConstant 'foo'; print "prototype: '",prototype(\&foo)//'undef',"'\n"; print Dumper (\&foo); print "foo(): ",scalar(foo()),"\n"; print "prototype: '",prototype(\&foo)//'undef',"'\n"; print Dumper (\&foo); print "foo(): ",scalar(foo()),"\n"; print "prototype: '",prototype(\&foo)//'undef',"'\n"; print Dumper (\&foo); # wantarray # return print "\n"; sub bar { print "bar runs\n"; return (123, 456); } BEGIN { print "\n"; { my $x = bar(); print "bar() x: $x\n"; } print "bar() scalar: ",scalar(bar()),"\n"; } use Memoize::ToConstant 'bar'; print "bar(): ",bar(),"\n"; print "bar(): ",bar(),"\n"; print "\n"; sub quux { print "quux runs\n"; my @x = (123, 456); return @x; } BEGIN { print "\n"; { my $x = quux(); print "quux() x: $x\n"; } print "quux() scalar: ",scalar(quux()),"\n"; print "\n"; } use Memoize::ToConstant 'quux'; print "quux(): ",quux(),"\n"; print "quux(): ",quux(),"\n"; exit 0; constant-defer-5/devel/run.pl0000644000175000017500000000360311424406742014156 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use warnings; { sub make_subr { return sub { 123 }; } my $x = make_subr(); require Scalar::Util; require Data::Dumper; Scalar::Util::weaken($x); print Data::Dumper->Dump([\$x],['x']); # require Devel::FindRef; # print Devel::FindRef::track(\$x); no warnings 'redefine'; *make_subr = sub {}; print Data::Dumper->Dump([\$x],['x']); sub make_two { my ($a) = @_; return sub { $a }; } $x = make_two(123); my $y = make_two(456); Scalar::Util::weaken($x); #Scalar::Util::weaken($y); print Data::Dumper->Dump([\$x],['x']); print Data::Dumper->Dump([\$y],['y']); exit 0; } { use constant::defer my_ctime => sub { return 123; #require POSIX; #return POSIX::ctime(time()); }; my $orig = \&my_ctime; print my_ctime(),"\n"; my $const = \&my_ctime; print "orig $orig\n"; print "const $const\n"; print "subr ",$constant::defer::DEBUG_LAST_SUBR,"\n"; require Scalar::Util; Scalar::Util::weaken($constant::defer::DEBUG_LAST_SUBR); print "subr ",$constant::defer::DEBUG_LAST_SUBR,"\n"; exit 0; } constant-defer-5/devel/Singleton/0002755000175000017500000000000011525332617014760 5ustar ggggconstant-defer-5/devel/Singleton/Const.pm0000644000175000017500000000463511256300311016375 0ustar gggg# This was an idea to have a Class::Singleton form with the inherited # ->instance installing a constant sub as the class ->instance, on the first # call. # # The difference is thus in holding the instance in a constant sub as # opposed to the way Class::Singleton does it in a package variable. It has # to build and lookup that variable each time, whereas a constant sub would # be hit directly by the method lookup. On the whole very little between # the two in either time or space ... # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . package Class::Singleton::Const; use strict; use warnings; use Carp; sub instance { my ($class) = @_; my $instance = $class->_new_instance; my $funcname = "${class}::instance"; { no strict 'refs'; no warnings; *$funcname = sub () { $instance }; } # constant.pm optimizes to save a typeglob, but it doesn't allow a # particular package to be given, only the caller() package # require constant; # constant->import ("${class}::instance", $instance); require constant; $_ = $instance; eval "package \Q$class\E; use constant instance => \$_; 1" or die $@; return $instance; } sub _new_instance { my ($class) = @_; croak "Singleton: $class->_new_instance() not defined"; } 1; __END__ # BEGIN { # print $xyz; # eval "no strict"; # print $xyz; # } # package x\;y; package MyClass; our @ISA = ('Class::Singleton::Const'); sub new { my ($class) = @_; return bless {}, $class; } *_new_instance = \&new; package main; print exists(&MyClass::instance),"\n"; print MyClass->instance,"\n"; print exists(&MyClass::instance),"\n"; 1; __END__ our $x = [ 'x' ]; print "$funcname\n"; my $y = $x; # use Data::Dumper; # print Dumper(\*$funcname),"\n"; require Scalar::Util; Scalar::Util::weaken ($x); constant-defer-5/devel/name.pl0000644000175000017500000000265211424406742014275 0ustar gggg#!/usr/bin/perl -w # Copyright 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use warnings; use Sub::Identify; use Data::Dumper; use constant foo => 123; BEGIN { my $symtab = \%main::; print Data::Dumper->Dump([$symtab->{'foo'}], ['foo']); } print "foo ",Sub::Identify::sub_fullname(\&foo),"\n"; BEGIN { my $symtab = \%main::; print Data::Dumper->Dump([$symtab->{'foo'}], ['foo']); } our $exglob = 999; use constant exglob => 123; print "exglob ",Sub::Identify::sub_fullname(\&exglob),"\n"; use constant::defer bar => sub { 456 }; print "bar ",Sub::Identify::sub_fullname(\&bar),"\n"; require Glib; print "FALSE ",Sub::Identify::sub_fullname(\&Glib::FALSE),"\n"; print "MAJOR_VERSION ",Sub::Identify::sub_fullname(\&Glib::MAJOR_VERSION)," ",Glib::MAJOR_VERSION(),"\n"; 1; constant-defer-5/devel/walk.pl0000644000175000017500000000334111424406741014306 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use 5.010; use strict; use warnings; use B; use B::Utils; use Devel::Peek; use Data::Dumper; use constant::defer FOO => sub { 123 }; Dump (\&FOO); my $c = B::svref_2object(\&FOO); say $c; my $op = $c->ROOT; say "op $op"; B::Utils::walkoptree_simple($op, sub { my ($op) = @_; say "walk $op ",$op->name," ",$op->targ; }); __END__ # B::walkoptree($op, 'main::myop'); # sub myop { # my ($op) = @_; # say "myop ",$op; # } exit 0; my $pad = $c->PADLIST; say "pad ",$pad," fill ",$pad->FILL," max ",$pad->MAX; { my $ref = $pad->object_2svref; say "pad ",Dumper(\$ref); } my @pa = $pad->ARRAY; say "pa ",@pa; # $a," fill ",$a->FILL," max ",$a->MAX; foreach my $a (@pa) { say "a ",$a; my @aa = $pad->ARRAY; say " aa ",@aa; # $a," fill ",$a->FILL," max ",$a->MAX; foreach my $b (@aa) { say " ",$b; my $ref = $b->object_2svref; say " ",Dumper(\$ref); my @bb = $b->ARRAY; say " bb ",@bb;< } } exit 0; constant-defer-5/examples/0002755000175000017500000000000011525332617013535 5ustar ggggconstant-defer-5/examples/simple.pl0000755000175000017500000000162711524150764015372 0ustar gggg#!/usr/bin/perl -w # Copyright 2009, 2010, 2011 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as published # by the Free Software Foundation; either version 3, or (at your option) any # later version. # # constant-defer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use constant::defer FOO => sub { print "now calculating FOO ...\n"; print " ... done\n"; return 12345; }; printf "FOO is %d\n", FOO; printf "FOO is %d\n", FOO; exit 0; constant-defer-5/examples/instance.pl0000755000175000017500000000416511524150765015706 0ustar gggg#!/usr/bin/perl -w # Copyright 2009, 2010, 2011 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as published # by the Free Software Foundation; either version 3, or (at your option) any # later version. # # constant-defer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . # Usage: ./instance.pl # # This is roughly how to press constant::defer into service for a once-only # object instance creation. # # The creation code here is entirely within the instance() routine so after # it's run it's discarded, which may save a few bytes of memory. If you # wanted other object instances as well as a shared one then you'd split out # a usual sort of new(). # # The $class parameter can help subclassing. A call like # # MyClass::SubClass->instance # # blesses into that subclass. But effectively there's only one instance # behind the two MyClass and MyClass::SubClass and whichever runs first is # the class created. If you only ever want one of the two then that can be # fine, otherwise it might be very bad. # # There's no reason not to take other arguments in the instance() creation, # except that they only have an effect on the first call, so it may be more # confusing than flexible. # # Generally you're best off using Class::Singleton (or # Class::Singleton::Weak) but if you've got constant::defer for other things # then this is compact and cute. # package MyClass; use strict; use constant::defer instance => sub { my ($class) = @_; return bless { foo => 123 }, $class; }; sub do_something { print "do something ...\n"; } package main; printf "instance %s\n", MyClass->instance; printf "instance %s\n", MyClass->instance; my $obj = MyClass->instance; $obj->do_something; exit 0; constant-defer-5/COPYING0000644000175000017500000010437410641206144012752 0ustar gggg GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . constant-defer-5/Changes0000644000175000017500000000201111524151263013175 0ustar ggggCopyright 2009, 2010, 2011 Kevin Ryde This file is part of constant-defer. constant-defer is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. constant-defer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with constant-defer. If not, see . Version 5, February 2011 - fixes for perl 5.6 and earlier Version 4, September 2010 - docs clarify not inlined, as suggested by Adam Kennedy Version 3, September 2010 - test manifest only as an author test Version 2, October 2009 - avoid a circular ref in the initial sub created Version 1, September 2009 - the first version constant-defer-5/t/0002755000175000017500000000000011525332617012162 5ustar ggggconstant-defer-5/t/MyTestHelpers.pm0000644000175000017500000001625711524101766015277 0ustar gggg# MyTestHelpers.pm -- my shared test script helpers # Copyright 2008, 2009, 2010, 2011 Kevin Ryde # MyTestHelpers.pm is shared by several distributions. # # MyTestHelpers.pm is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 3, or (at your option) any later # version. # # MyTestHelpers.pm is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this file. If not, see . package MyTestHelpers; use strict; use Exporter; use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); @ISA = ('Exporter'); @EXPORT_OK = qw(findrefs main_iterations warn_suppress_gtk_icon glib_gtk_versions any_signal_connections nowarnings); %EXPORT_TAGS = (all => \@EXPORT_OK); sub DEBUG { 0 } #----------------------------------------------------------------------------- { my $warning_count; my $stacktraces; my $stacktraces_count = 0; sub nowarnings_handler { $warning_count++; if ($stacktraces_count < 3 && eval { require Devel::StackTrace }) { $stacktraces_count++; $stacktraces .= "\n" . Devel::StackTrace->new->as_string() . "\n"; } warn @_; } sub nowarnings { $SIG{'__WARN__'} = \&nowarnings_handler; } END { if ($warning_count) { diag("Saw $warning_count warning(s):"); if (defined $stacktraces) { diag($stacktraces); } else { diag('(Devel::StackTrace not available for backtrace)'); } diag("Exit code 1 for warnings"); $? = 1; } } } sub diag { if (Test::More->can('diag')) { Test::More::diag (@_); } else { my $msg = join('', map {defined($_)?$_:'[undef]'} @_)."\n"; $msg =~ s/^/# /mg; print STDERR $msg; } } sub dump { my ($thing) = @_; if (eval { require Data::Dumper; 1 }) { diag (Data::Dumper::Dumper ($thing)); } else { diag ("Data::Dumper not available"); } } #----------------------------------------------------------------------------- # Test::Weaken and other weaking sub findrefs { my ($obj) = @_; require Test::More; defined $obj or return; require Scalar::Util; if (ref $obj && Scalar::Util::reftype($obj) eq 'HASH') { Test::More::diag ("Keys: ", join(' ', map {"$_=$obj->{$_}"} keys %$obj)); } if (eval { require Devel::FindRef }) { Test::More::diag (Devel::FindRef::track($obj, 8)); } else { Test::More::diag ("Devel::FindRef not available -- $@\n"); } } sub test_weaken_show_leaks { my ($leaks) = @_; $leaks || return; eval { # explain new in 0.82 Test::More::diag ("Test-Weaken ",Test::More::explain($leaks)); }; my $unfreed = $leaks->unfreed_proberefs; foreach my $proberef (@$unfreed) { Test::More::diag (" unfreed $proberef"); } foreach my $proberef (@$unfreed) { Test::More::diag ("search $proberef"); MyTestHelpers::findrefs($proberef); } } #----------------------------------------------------------------------------- # Gtk/Glib helpers # Gtk 2.16 can go into a hard loop on events_pending() / main_iteration_do() # if dbus is not running, or something like that. In any case limiting the # iterations is good for test safety. # sub main_iterations { require Test::More; my $count = 0; if (DEBUG) { Test::More::diag ("main_iterations() ..."); } while (Gtk2->events_pending) { $count++; Gtk2->main_iteration_do (0); if ($count >= 500) { Test::More::diag ("main_iterations(): oops, bailed out after $count events/iterations"); return; } } Test::More::diag ("main_iterations(): ran $count events/iterations"); } # warn_suppress_gtk_icon() is a $SIG{__WARN__} handler which suppresses spam # from Gtk trying to make you buy the hi-colour icon theme. Eg, # # { # local $SIG{'__WARN__'} = \&MyTestHelpers::warn_suppress_gtk_icon; # $something = SomeThing->new; # } # sub warn_suppress_gtk_icon { my ($message) = @_; unless ($message =~ /Gtk-WARNING.*icon/) { warn @_; } } sub glib_gtk_versions { require Test::More; my $gtk2_loaded = Gtk2->can('init'); my $glib_loaded = Glib->can('get_home_dir'); if ($gtk2_loaded) { Test::More::diag ("Perl-Gtk2 version ",Gtk2->VERSION); } if ($glib_loaded) { # when loaded Test::More::diag ("Perl-Glib version ",Glib->VERSION); Test::More::diag ("Compiled against Glib version ", Glib::MAJOR_VERSION(), ".", Glib::MINOR_VERSION(), ".", Glib::MICRO_VERSION(), "."); Test::More::diag ("Running on Glib version ", Glib::major_version(), ".", Glib::minor_version(), ".", Glib::micro_version(), "."); } if ($gtk2_loaded) { Test::More::diag ("Compiled against Gtk version ", Gtk2::MAJOR_VERSION(), ".", Gtk2::MINOR_VERSION(), ".", Gtk2::MICRO_VERSION(), "."); Test::More::diag ("Running on Gtk version ", Gtk2::major_version(), ".", Gtk2::minor_version(), ".", Gtk2::micro_version(), "."); } } # Return true if there's any signal handlers connected to $obj. # # Signal IDs are from 1 up, don't pass 0 to signal_handler_is_connected() # since in Glib 2.4.1 it spits out a g_log() error. # sub any_signal_connections { my ($obj) = @_; my @connected = grep {$obj->signal_handler_is_connected ($_)} (1 .. 500); if (@connected) { my $connected = join(',',@connected); Test::More::diag ("$obj signal handlers connected: $connected"); return $connected; } return undef; } # wait for $signame to be emitted on $widget, with a timeout sub wait_for_event { my ($widget, $signame) = @_; require Test::More; if (DEBUG) { Test::More::diag ("wait_for_event() $signame on $widget"); } my $done = 0; my $got_event = 0; my $sig_id = $widget->signal_connect ($signame => sub { if (DEBUG) { Test::More::diag ("wait_for_event() $signame received"); } $done = 1; return 0; # Gtk2::EVENT_PROPAGATE (new in Gtk2 1.220) }); my $timer_id = Glib::Timeout->add (30_000, # 30 seconds sub { $done = 1; Test::More::diag ("wait_for_event() oops, timeout waiting for $signame on $widget"); return 1; # Glib::SOURCE_CONTINUE (new in Glib 1.220) }); if ($widget->can('get_display')) { # GdkDisplay new in Gtk 2.2 $widget->get_display->sync; } else { # in Gtk 2.0 gdk_flush() is a sync actually Gtk2::Gdk->flush; } my $count = 0; while (! $done) { if (DEBUG >= 2) { Test::More::diag ("wait_for_event() iteration $count"); } Gtk2->main_iteration; $count++; } Test::More::diag ("wait_for_event(): '$signame' ran $count events/iterations\n"); $widget->signal_handler_disconnect ($sig_id); Glib::Source->remove ($timer_id); } 1; __END__ constant-defer-5/t/constant-defer.t0000755000175000017500000002320411524156223015261 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010, 2011 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use constant::defer; use Test; BEGIN { plan tests => 49; } use lib 't'; use MyTestHelpers; MyTestHelpers::nowarnings(); sub streq_array { my ($a1, $a2) = @_; while (@$a1 && @$a2) { unless ((! defined $a1->[0] && ! defined $a2->[0]) || (defined $a1->[0] && defined $a2->[0] && $a1->[0] eq $a2->[0])) { return 0; } shift @$a1; shift @$a2; } return (@$a1 == @$a2); } #------------------------------------------------------------------------------ # VERSION { my $want_version = 5; ok ($constant::defer::VERSION, $want_version, 'VERSION variable'); ok (constant::defer->VERSION, $want_version, 'VERSION class method'); ok (eval { constant::defer->VERSION($want_version); 1 }, 1, "VERSION class check $want_version"); my $check_version = $want_version + 1000; ok (! eval { constant::defer->VERSION($check_version); 1 }, 1, "VERSION class check $check_version"); } #------------------------------------------------------------------------------ # plain name my $have_weaken; my $skip_weaken; { my $foo_runs = 0; use constant::defer FOO => sub { $foo_runs++; return 123 }; my $orig_code; $orig_code = \&FOO; ok (FOO, 123, 'FOO first run'); ok ($foo_runs, 1, 'FOO first runs code'); ok (&$orig_code(), 123, 'FOO orig second run'); ok ($foo_runs, 1, "FOO orig second doesn't run code"); $have_weaken = eval { require Scalar::Util; my $x = [ 'hello' ]; Scalar::Util::weaken($x); if (defined $x) { die "Oops, weakening didn't garbage collect"; } 1 }; if (! $have_weaken) { MyTestHelpers::diag ("Scalar::Util::weaken() not available -- ",$@); $skip_weaken = 'due to Scalar::Util::weaken() not available'; } { if ($have_weaken) { Scalar::Util::weaken ($orig_code); } skip ($skip_weaken, ! defined $orig_code, 1, 'orig FOO code garbage collected'); $foo_runs = 0; ok (FOO, 123, 'FOO second run'); ok ($foo_runs, 0, "FOO second doesn't run code"); } } #------------------------------------------------------------------------------ # fully qualified name { my $runs = 0; use constant::defer 'Some::Non::Package::Place::func' => sub { $runs = 1; return 'xyz' }; ok (Some::Non::Package::Place::func(), 'xyz', 'explicit package first run'); ok ($runs, 1, 'explicit package first run runs code'); $runs = 0; ok (Some::Non::Package::Place::func(), 'xyz', 'explicit package second run'); ok ($runs, 0, 'explicit package second run doesn\'t run code'); } #------------------------------------------------------------------------------ # array value { my $runs = 0; use constant::defer THREE => sub { $runs = 1; return ('a','b','c') }; ok (streq_array ([ THREE() ], [ 'a', 'b', 'c' ]), 1, 'THREE return values first run'); ok ($runs, 1, 'THREE return values first run runs code'); $runs = 0; ok (streq_array([ THREE() ], [ 'a', 'b', 'c' ]), 1, 'THREE return values second run'); ok ($runs, 0, 'THREE return values second run doesn\'t run code'); } { my $runs = 0; use constant::defer THREE_SCALAR => sub { $runs = 1; return ('a','b','c') }; my $got = THREE_SCALAR(); ok ($got, 3, 'three values in scalar context return values first run'); ok ($runs, 1, 'three values in scalar context return values first run runs code'); $runs = 0; $got = THREE_SCALAR(); ok ($got, 3, 'three values in scalar context return values second run'); ok ($runs, 0, 'three values in scalar context return values second run doesn\'t run code'); } #------------------------------------------------------------------------------ # multiple names { use constant::defer PAIR_ONE => sub { 123 }, PAIR_TWO => sub { 456 }; ok (PAIR_ONE, 123, 'PAIR_ONE'); ok (PAIR_TWO, 456, 'PAIR_TWO'); } { use constant::defer { HASH_ONE => sub { 123 }, HASH_TWO => sub { 456 } }; ok (HASH_ONE, 123, 'HASH_ONE'); ok (HASH_TWO, 456, 'HASH_TWO'); } { use constant::defer SHASH_ONE => sub { 123 }, { SHASH_TWO => sub { 456 }, SHASH_THREE => sub { 789 } }; ok (SHASH_ONE, 123, 'SHASH_ONE'); ok (SHASH_TWO, 456, 'SHASH_TWO'); ok (SHASH_THREE, 789, 'SHASH_THREE'); } #------------------------------------------------------------------------------ # with can() { my $runs = 0; package MyTestCan; use constant::defer CANNED => sub { $runs++; return 'foo' }; package main; my $func = MyTestCan->can('CANNED'); my $got = &$func(); ok ($got, 'foo', 'through can() - result'); ok ($runs, 1, 'through can() - run once'); $got = &$func(); ok ($got, 'foo', 'through can() - 2nd result'); ok ($runs, 1, 'through can() - 2nd still run once'); } #------------------------------------------------------------------------------ # with Exporter import() { my $runs = 0; package MyTestImport; use vars qw(@ISA @EXPORT); use constant::defer TEST_IMPORT_FOO => sub { $runs++; return 'foo' }; require Exporter; @ISA = ('Exporter'); @EXPORT = ('TEST_IMPORT_FOO'); package main; MyTestImport->import; my $got = TEST_IMPORT_FOO(); ok ($got, 'foo', 'through import - result'); ok ($runs, 1, 'through import - run once'); $got = TEST_IMPORT_FOO(); ok ($got, 'foo', 'through import - 2nd result'); ok ($runs, 1, 'through import - 2nd still run once'); } #------------------------------------------------------------------------------ # gc of supplied $subr after it's been called { my $subr; BEGIN { # crib: anon sub must refer to a lexical or isn't gc'ed, at least in 5.6.0 my $lexical_var = 'gc me'; $subr = sub { return $lexical_var }; } use constant::defer WEAKEN_CONST => $subr; # including when the can() first func is retained # my $cancode = main->can('WEAKEN_CONST'); my @got = WEAKEN_CONST(); ok (streq_array (\@got, ['gc me']), 1, 'WEAKEN_CONST - result'); if ($have_weaken) { Scalar::Util::weaken ($subr); } skip ($skip_weaken, ! defined $subr, 1, 'WEAKEN_CONST - subr now undef'); } { my ($objref, $subr); my $runs = 0; BEGIN { my %obj = (foo => 'bar'); $subr = sub { $runs++; return %obj }; $objref = \%obj; } use constant::defer WEAKEN_OBJRET => $subr; # including when the can() first func is retained # my $cancode = main->can('WEAKEN_OBJRET'); my @got = WEAKEN_OBJRET(); ok (streq_array (\@got, ['foo','bar']), 1, 'WEAKEN_OBJRET - result'); ok ($runs, 1, 'WEAKEN_OBJRET - run once'); if ($have_weaken) { Scalar::Util::weaken ($subr); Scalar::Util::weaken ($objref); } skip ($skip_weaken, ! defined $subr, 1, 'WEAKEN_OBJRET - subr now undef'); skip ($skip_weaken, ! defined $objref, 1, 'WEAKEN_OBJRET - objref now undef'); } #------------------------------------------------------------------------------ # gc of can() after called { use constant::defer CAN_GC => sub { return 'gc me' }; my $cancode = main->can('CAN_GC'); my @got = CAN_GC(); ok (streq_array (\@got, ['gc me']), 1, 'CAN_GC - result'); if ($have_weaken) { Scalar::Util::weaken ($cancode); } skip ($skip_weaken, ! defined $cancode, 1, 'CAN_GC - can() coderef now undef'); } #------------------------------------------------------------------------------ # gc of initial definition after called { use constant::defer INITIAL_GC => sub { return 'gc me' }; my $coderef = \&INITIAL_GC; my @got = INITIAL_GC(); ok (streq_array (\@got, ['gc me']), 1, 'INITIAL_GC - result'); if ($have_weaken) { Scalar::Util::weaken ($coderef); } skip ($skip_weaken, ! defined $coderef, 1, 'INITIAL_GC - saved initial now undef'); } #------------------------------------------------------------------------------ # gc of runner helper after redefine { use constant::defer RUNNER_GC => sub { return 'gc me' }; my $runner; BEGIN { $runner = $constant::defer::DEBUG_LAST_RUNNER; undef $constant::defer::DEBUG_LAST_RUNNER; } if (! $runner) { MyTestHelpers::diag ("DEBUG_LAST_RUNNER not enabled in defer.pm"); } do { local $^W = 0; # no warnings 'redefine'; eval '*RUNNER_GC = sub () { "new value" }; 1'; } or die "Oops, eval error: $@"; if ($have_weaken) { Scalar::Util::weaken ($runner); } skip ($skip_weaken, ! defined $runner, 1, 'RUNNER_GC - now undef'); if ($runner) { require Devel::FindRef; MyTestHelpers::diag (Devel::FindRef::track($runner)); } } exit 0; constant-defer-5/MANIFEST0000644000175000017500000000151711525332617013052 0ustar ggggChanges COPYING debian/changelog debian/compat debian/control debian/copyright debian/rules debian/source/format debian/watch devel/circular.pl devel/import.pl devel/junk/Attribute-MemoizeToConstant.pm devel/Memoize/t-memoize-toconst-2.pl devel/Memoize/t-memoize-toconst.pl devel/Memoize/ToConstant.pm devel/Memoize/ToConstant.t devel/MyConstantDeferExport.pm devel/name.pl devel/package-constants.pl devel/run.pl devel/Singleton/Const.pm devel/walk.pl examples/instance.pl examples/simple.pl inc/my_pod2html inc/MyMakeMakerExtras.pm lib/constant/defer.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP README SIGNATURE t/constant-defer.t t/MyTestHelpers.pm xt/0-META-read.t xt/0-Test-DistManifest.t xt/0-Test-Pod.t xt/0-Test-Synopsis.t xt/0-Test-YAML-Meta.t META.yml Module meta-data (added by MakeMaker) constant-defer-5/inc/0002755000175000017500000000000011525332617012470 5ustar ggggconstant-defer-5/inc/my_pod2html0000644000175000017500000000750111513475401014646 0ustar gggg#!/usr/bin/perl # my_pod2html -- convert POD to HTML, with some mangling # Copyright 2009, 2010, 2011 Kevin Ryde # my_pod2html is shared by several distributions. # # my_pod2html is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # my_pod2html is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along # with this file. If not, see . use strict; use warnings; #use Smart::Comments; my $pod2html = MyPod2HTML->new; #

and

both too big, in mozilla at least $pod2html->html_h_level(3); $pod2html->parse_from_file(@ARGV); exit 0; package MyPod2HTML; use base 'Pod::Simple::HTML'; our $VERSION = 1; use constant DEBUG => 0; my %table = ('apt-file' => 'http://packages.debian.org/apt-file', 'apt-cache' => 'http://packages.debian.org/apt', 'apt-rdepends' => 'http://packages.debian.org/apt-rdepends', 'gtk-options' => 'http://manpages.ubuntu.com/manpages/jaunty/man7/gtk-options.7.html', 'xsetroot' => 'http://www.x.org/archive/X1'.'1R7.5/doc/man/man1/xsetroot.1.html', 'leafnode' => 'http://leafnode.sourceforge.net', 'lynx' => 'http://lynx.isc.org/', 'feed2imap' => 'http://home.gna.org/feed2imap', # disguise from grep 'rss'.'2email' => 'http://rss'.'2email.infogami.com', 'rssdrop' => 'http://search.cpan.org/dist/rssdrop/', 'toursst' => 'http://packages.debian.org/etch/toursst', 'netrc' => 'http://linux.die.net/man/5/netrc', # no online man pages apparently at http://man-db.nongnu.org/ 'man' => 'http://ftp.parisc-linux.org/cgi-bin/man/man2html?man+1', 'lexgrog' => 'http://ftp.parisc-linux.org/cgi-bin/man/man2html?lexgrog+1', 'apropos' => 'http://ftp.parisc-linux.org/cgi-bin/man/man2html?apropos+1', ); sub resolve_man_page_link { my ($self, $to, $frag) = @_; $to = "$to"; # Pod::Simple::LinkSection object ### $to if (my ($page, $section) = ($to =~ /(.*)\(\d+\)$/)) { ### $page if (my $url = $table{$page}) { return $url; } } return shift->SUPER::resolve_man_page_link (@_); } sub resolve_pod_link_by_table { my ($self, $to, $section) = @_; my $url; if (defined $to) { if ($to eq 'AptPkg') { $url = 'http://packages.debian.org/libapt-pkg-perl'; } if ($to =~ /^Glib::Ex::(SourceIds|SignalIds|FreezeNotify|TieProperties)/) { $url = "http://user42.tuxfamily.org/glib-ex-ob"."jectbits/$1.html"; } if ($to eq 'Gtk2::Ex::Widget'.'Cursor') { $url = "http://user42.tuxfamily.org/glib-ex-widget'.'cursor/Widget'.'Cursor.html"; } if ($to eq 'Ti'.'e:'.':TZ') { $url = 'http://user42.tuxfamily.org/ti'.'e-'.'tz/TZ.html'; } if ($to eq 'Time:'.':TZ') { $url = 'http://user42.tuxfamily.org/ti'.'e-'.'tz/Time-'.'TZ.html'; } if ($to =~ /^(Glib|Gtk2)($|::(?!Ex::))/) { $to =~ s{::}{/}; $url = "http://gtk2-perl.sourceforge.net/doc/pod/$to.html" } if (defined $url) { return ($url . (defined $section && $section ne '' ? "#$section" : '')); } } return $self->SUPER::resolve_pod_link_by_table($to, $section); } # sub do_pod_link { # my($self, $link) = @_; # if (DEBUG) { # print "\nlink tag=",$link->tagname," type=",$link->attr('type'),"\n"; # print " to=",$link->attr('to')||'[none]',"\n"; # print " section=",$link->attr('section')||'[none]',"\n"; # } # # my $to = $link->attr('to') || ''; # undef if internal link # # return $self->SUPER::do_pod_link($link); # } constant-defer-5/inc/MyMakeMakerExtras.pm0000644000175000017500000003327611523705124016364 0ustar gggg# MyMakeMakerExtra.pm -- my shared MakeMaker extras # Copyright 2009, 2010, 2011 Kevin Ryde # MyMakeMakerExtras.pm is shared by several distributions. # # MyMakeMakerExtras.pm is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 3, or (at your option) any later # version. # # MyMakeMakerExtras.pm is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this file. If not, see . package MyMakeMakerExtras; use strict; # uncomment this to run the ### lines #use Smart::Comments; my %my_options; sub WriteMakefile { my %opts = @_; if (exists $opts{'META_MERGE'}) { # cf. ExtUtils::MM_Any::metafile_data() default ['t','inc'] foreach ('devel', 'examples', 'junk', 'maybe') { my $dir = $_; if (-d $dir) { push @{$opts{'META_MERGE'}->{'no_index'}->{'directory'}}, $dir; } } $opts{'META_MERGE'}->{'resources'}->{'license'} ||= 'http://www.gnu.org/licenses/gpl.html'; _meta_merge_shared_tests (\%opts); _meta_merge_shared_devel (\%opts); } $opts{'clean'}->{'FILES'} .= ' temp-lintian $(MY_HTML_FILES)'; $opts{'realclean'}->{'FILES'} .= ' TAGS'; if (! defined &MY::postamble) { *MY::postamble = \&MyMakeMakerExtras::postamble; } foreach ('MyMakeMakerExtras_Pod_Coverage', 'MyMakeMakerExtras_LINT_FILES', 'MY_NO_HTML', 'MY_EXTRA_FILE_PART_OF') { $my_options{$_} = delete $opts{$_}; } ### chain to WriteMakefile() ### %opts ExtUtils::MakeMaker::WriteMakefile (%opts); ### done } sub strip_comments { my ($str) = @_; $str =~ s/^\s*#.*\n//mg; $str } #------------------------------------------------------------------------------ # META_MERGE sub _meta_merge_shared_tests { my ($opts) = @_; if (-e 'xt/0-Test-Pod.t') { _meta_merge_req_add (_meta_merge_maximum_tests($opts), 'Test::Pod' => '1.00'); } if (-e 'xt/0-Test-DistManifest.t') { _meta_merge_req_add (_meta_merge_maximum_tests($opts), 'Test::DistManifest' => 0); } if (-e 'xt/0-Test-Synopsis.t') { _meta_merge_req_add (_meta_merge_maximum_tests($opts), 'Test::Synopsis' => 0); } if (-e 'xt/0-Test-YAML-Meta.t') { _meta_merge_req_add (_meta_merge_maximum_tests($opts), 'Test::YAML::Meta' => '0.15'); } if (-e 'xt/0-META-read.t') { if (_min_perl_version_lt ($opts, 5.00307)) { _meta_merge_req_add (_meta_merge_maximum_tests($opts), 'FindBin' => 0); } if (_min_perl_version_lt ($opts, 5.00405)) { _meta_merge_req_add (_meta_merge_maximum_tests($opts), 'File::Spec' => 0); } _meta_merge_req_add (_meta_merge_maximum_tests($opts), 'YAML' => 0, 'YAML::Syck' => 0, 'YAML::Tiny' => 0, 'YAML::XS' => 0, 'Parse::CPAN::Meta' => 0); } } # return hashref of "maximum_tests" under $opts, created if necessary sub _meta_merge_maximum_tests { my ($opts) = @_; $opts->{'META_MERGE'}->{'optional_features'}->{'maximum_tests'} ||= { description => 'Have "make test" do as much as possible.', requires => { }, }; return $opts->{'META_MERGE'}->{'optional_features'}->{'maximum_tests'}->{'requires'}; } sub _meta_merge_shared_devel { my ($opts) = @_; _meta_merge_req_add (_meta_merge_maximum_devel($opts), # the "make unused" target below 'warnings::unused' => 0); if (-e 'inc/my_pod2html') { if (_min_perl_version_lt ($opts, 5.009003)) { _meta_merge_req_add (_meta_merge_maximum_devel($opts), 'Pod::Simple::HTML' => 0); } } } # return hashref of "maximum_devel" under $opts, created if necessary sub _meta_merge_maximum_devel { my ($opts) = @_; $opts->{'META_MERGE'}->{'optional_features'}->{'maximum_devel'} ||= { description => 'Stuff used variously for development.', requires => { }, }; return $opts->{'META_MERGE'}->{'optional_features'}->{'maximum_devel'}->{'requires'}; } # return true if MIN_PERL_VERSION in $opts is < $ver, or no MIN_PERL_VERSION sub _min_perl_version_lt { my ($opts, $perlver) = @_; return (! defined $opts->{'MIN_PERL_VERSION'} || $opts->{'MIN_PERL_VERSION'} < $perlver); } sub _meta_merge_req_add { my $req = shift; ### MyMakeMakerExtras META_MERGE: @_ while (@_) { my $module = shift; my $version = shift; if (defined $req->{$module}) { if ($req->{$module} > $version) { $version = $req->{$module}; } } $req->{$module} = $version; } } #------------------------------------------------------------------------------ # postamble() sub postamble { my ($makemaker) = @_; ### MyMakeMakerExtras postamble(): $makemaker my $post = $my_options{'postamble_docs'}; my @exefiles_html; my @pmfiles_html; unless ($my_options{'MY_NO_HTML'}) { $post .= <<'HERE'; #------------------------------------------------------------------------------ # docs stuff -- from inc/MyMakeMakerExtras.pm MY_POD2HTML = $(PERL) inc/my_pod2html HERE my $munghtml_extra = $makemaker->{'MY_MUNGHTML_EXTRA'}; if ($munghtml_extra) { $post =~ s/apt-file!'/apt-file!'\\ $munghtml_extra/; } my @pmfiles = keys %{$makemaker->{'PM'}}; @pmfiles = grep {!/\.mo$/} @pmfiles; # not LocaleData .mo files my @exefiles = (defined $makemaker->{'EXE_FILES'} ? @{$makemaker->{'EXE_FILES'}} : ()); my %html_files; my $html_rule = sub { my ($pm) = @_; my $fullhtml = $pm; $fullhtml =~ s{lib/}{}; # remove lib/ $fullhtml =~ s{\.p[ml]$}{}; # remove .pm or .pl $fullhtml .= '.html'; my $parthtml = $fullhtml; $fullhtml =~ s{/}{-}g; # so Foo-Bar.html unless ($html_files{$fullhtml}++) { $post .= <<"HERE"; $fullhtml: $pm Makefile \$(MY_POD2HTML) $pm >$fullhtml HERE } $parthtml =~ s{.*/}{}; # remove any directory part, just Bar.html unless ($html_files{$parthtml}++) { $post .= <<"HERE"; $parthtml: $pm Makefile \$(MY_POD2HTML) $pm >$parthtml HERE } return $parthtml; }; foreach (@exefiles) { push @exefiles_html, &$html_rule ($_); } foreach (@pmfiles) { push @pmfiles_html, &$html_rule ($_); } $post .= "MY_HTML_FILES = " . join(' ', keys %html_files) . "\n"; $post .= <<'HERE'; html: $(MY_HTML_FILES) HERE } $post .= <<'HERE'; #------------------------------------------------------------------------------ # development stuff -- from inc/MyMakeMakerExtras.pm version: $(NOECHO)$(ECHO) $(VERSION) HERE my $lint_files = $my_options{'MyMakeMakerExtras_LINT_FILES'}; if (! defined $lint_files) { $lint_files = 'Makefile.PL $(EXE_FILES) $(TO_INST_PM)'; # would prefer not to lock down the 't' dir existance at ./Makefile.PL # time, but it's a bit hard without without GNU make extensions if (-d 't') { $lint_files .= ' t/*.t'; } if (-d 'xt') { $lint_files .= ' xt/*.t'; } foreach ('examples', 'devel') { my $dir = $_; my $pattern = "$dir/*.pl"; if (glob ($pattern)) { $lint_files .= " $pattern"; } } } my $podcoverage = ''; foreach (@{$my_options{'MyMakeMakerExtras_Pod_Coverage'}}) { my $class = $_; # the "." obscures it from MyExtractUse.pm $podcoverage .= "\t-\$(PERLRUNINST) -e 'use "."Pod::Coverage package=>$class'\n"; } $post .= "LINT_FILES = $lint_files\n" . <<'HERE'; lint: perl -MO=Lint $(LINT_FILES) pc: HERE # "podchecker -warnings -warnings" too much reporting every < and > $post .= $podcoverage . <<'HERE'; -podlinkcheck -I lib `ls $(LINT_FILES) | grep -v '\.bash$$|\.desktop$$\.png$$|\.xpm$$'` -podchecker `ls $(LINT_FILES) | grep -v '\.bash$$|\.desktop$$\.png$$|\.xpm$$'` perlcritic $(LINT_FILES) unused: for i in $(LINT_FILES); do perl -Mwarnings::unused -I lib -c $$i; done HERE $post .= <<'HERE'; myman: -mv MANIFEST MANIFEST.old touch SIGNATURE (make manifest 2>&1; diff -u MANIFEST.old MANIFEST) |less # find files in the dist with mod times this year, but without this year in # the copyright line check-copyright-years: year=`date +%Y`; \ tar tvfz $(DISTVNAME).tar.gz \ | egrep "$$year-|debian/copyright" \ | sed 's:^.*$(DISTVNAME)/::' \ | (result=0; \ while read i; do \ GREP=grep; \ case $$i in \ '' | */ \ | ppport.h \ | debian/changelog | debian/compat | debian/doc-base \ | debian/patches/*.diff | debian/source/format \ | COPYING | MANIFEST* | SIGNATURE | META.yml \ | version.texi | */version.texi \ | *utf16* | examples/rs''s2lea''fnode.conf \ | */MathI''mage/ln2.gz | */MathI''mage/pi.gz \ | *.mo | *.locatedb* | t/samp.*) \ continue ;; \ *.gz) GREP=zgrep ;; \ esac; \ if test -e "$(srcdir)/$$i"; then f="$(srcdir)/$$i"; \ else f="$$i"; fi; \ if ! $$GREP -q "Copyright.*$$year" $$f; then \ echo "$$i":"1: this file"; \ grep Copyright $$f; \ result=1; \ fi; \ done; \ exit $$result) # only a DEBUG non-zero number is bad, so an expression can copy a debug from # another package check-debug-constants: if egrep -nH 'DEBUG => [1-9]|^[ \t]*use Smart::Comments' $(EXE_FILES) $(TO_INST_PM) t/*.t xt/*.t; then exit 1; else exit 0; fi check-spelling: if find . -type f | egrep -v '(Makefile|dist-deb)' | xargs egrep --color=always -nHi '[c]usor|[r]efering|[w]riteable|[n]ineth|\b[o]mmitt?ed|[o]mited|[$$][rd]elf|[r]equrie|[n]oticable|[c]ontinous|[e]xistant|[e]xplict|[a]gument|[d]estionation|\b[t]he the\b|\b[n]ote sure\b'; \ then false; else true; fi HERE $post .= "\n"; $post .= ("MY_EXTRA_FILE_PART_OF = " . ($my_options{'MY_EXTRA_FILE_PART_OF'}||'') . "\n"); $post .= <<'HERE'; check-file-part-of: if grep --text 'This file is'' part of ' -r . | egrep -iv '$(DISTNAME)$(MY_EXTRA_FILE_PART_OF)'; then false; else true; fi diff-prev: rm -rf diff.tmp mkdir diff.tmp cd diff.tmp \ && tar xfz ../$(DISTNAME)-`expr $(VERSION) - 1`.tar.gz \ && tar xfz ../$(DISTNAME)-$(VERSION).tar.gz -cd diff.tmp; diff -ur $(DISTNAME)-`expr $(VERSION) - 1` \ $(DISTNAME)-$(VERSION) >tree.diff -$${PAGER:-less} diff.tmp/tree.diff rm -rf diff.tmp # in a hash-style multi-const this "use constant" pattern only picks up the # first constant, unfortunately, but it's better than nothing TAG_FILES = $(TO_INST_PM) TAGS: $(TAG_FILES) etags \ --regex='{perl}/use[ \t]+constant\(::defer\)?[ \t]+\({[ \t]*\)?\([A-Za-z_][^ \t=,;]+\)/\3/' \ $(TAG_FILES) HERE my $have_XS = scalar %{$makemaker->{'XS'}}; my $arch = ($have_XS ? `dpkg --print-architecture` : 'all'); chomp($arch); my $debname = (defined $makemaker->{'EXE_FILES'} ? '$(DISTNAME)' : "\Llib$makemaker->{'DISTNAME'}-perl"); $post .= "DEBNAME = $debname\n" . "DPKG_ARCH = $arch\n" . <<'HERE'; DEBVNAME = $(DEBNAME)_$(VERSION)-1 DEBFILE = $(DEBVNAME)_$(DPKG_ARCH).deb # ExtUtils::MakeMaker 6.42 of perl 5.10.0 makes "$(DISTVNAME).tar.gz" depend # on "$(DISTVNAME)" distdir directory, which is always non-existent after a # successful dist build, so the .tar.gz is always rebuilt. # # So although the .deb depends on the .tar.gz don't express that here or it # rebuilds the .tar.gz every time. # # The right rule for the .tar.gz would be to depend on the files which go # into it of course ... # # DISPLAY is unset for making a deb since under fakeroot gtk stuff may try # to read config files like ~/.pangorc from root's home dir /root/.pangorc, # and that dir will be unreadable by ordinary users (normally), provoking # warnings and possible failures from nowarnings(). # $(DEBFILE) deb: test -f $(DISTVNAME).tar.gz || $(MAKE) $(DISTVNAME).tar.gz debver="`dpkg-parsechangelog -c1 | sed -n -r -e 's/^Version: (.*)-[0-9.]+$$/\1/p'`"; \ echo "debver $$debver", want $(VERSION); \ test "$$debver" = "$(VERSION)" rm -rf $(DISTVNAME) tar xfz $(DISTVNAME).tar.gz unset DISPLAY; export DISPLAY; \ cd $(DISTVNAME) \ && dpkg-checkbuilddeps debian/control \ && fakeroot debian/rules binary rm -rf $(DISTVNAME) lintian-deb: $(DEBFILE) lintian -i -X new-package-should-close-itp-bug $(DEBFILE) lintian-source: rm -rf temp-lintian; \ mkdir temp-lintian; \ cd temp-lintian; \ cp ../$(DISTVNAME).tar.gz $(DEBNAME)_$(VERSION).orig.tar.gz; \ tar xfz $(DEBNAME)_$(VERSION).orig.tar.gz; \ echo 'empty-debian-diff' \ >$(DISTVNAME)/debian/source.lintian-overrides; \ mv -T $(DISTVNAME) $(DEBNAME)-$(VERSION); \ dpkg-source -b $(DEBNAME)-$(VERSION) \ $(DEBNAME)_$(VERSION).orig.tar.gz; \ lintian -i -X missing-debian-source-format *.dsc; \ cd ..; \ rm -rf temp-lintian HERE { my $list_html = join(' ',@exefiles_html); if (! $list_html && @pmfiles_html <= 3) { $list_html = join(' ',@pmfiles_html); } if (! -e 'inc/my_pod2html') { $list_html = ''; } my $make_list_html = ($list_html ? "\n\tmake $list_html" : ""); $post .= <<"HERE"; my-list:$make_list_html ls -l -U $list_html \$(EXE_FILES) *.tar.gz *.deb HERE $post .= <<'HERE'; @echo -n '$(DEBFILE) ' @dpkg-deb -f $(DEBFILE) | grep Installed-Size HERE if ($list_html) { $post .= "\trm -f $list_html\n"; } } return $post; } 1; __END__ constant-defer-5/debian/0002755000175000017500000000000011525332617013141 5ustar ggggconstant-defer-5/debian/rules0000755000175000017500000000154111255533777014232 0ustar gggg#!/usr/bin/make -f # Copyright 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as published # by the Free Software Foundation; either version 3, or (at your option) any # later version. # # constant-defer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/perlmodule.mk DEB_INSTALL_EXAMPLES_libconstant-defer-perl = examples/* constant-defer-5/debian/compat0000644000175000017500000000000111255532716014336 0ustar gggg5constant-defer-5/debian/changelog0000644000175000017500000000021711525332600015001 0ustar gggglibconstant-defer-perl (5-1) unstable; urgency=low * Packaged version. -- Kevin Ryde Sat, 12 Feb 2011 09:17:35 +1100 constant-defer-5/debian/source/0002755000175000017500000000000011525332617014441 5ustar ggggconstant-defer-5/debian/source/format0000644000175000017500000000000411357715142015645 0ustar gggg1.0 constant-defer-5/debian/watch0000644000175000017500000000171411255534010014162 0ustar gggg# Web site version watch, for devscripts uscan program. # Copyright 2009 Kevin Ryde # # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 3, or # (at your option) any later version. # # constant-defer is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with constant-defer. If not, see . # Crib notes: # "man uscan" describes the format. # test with: uscan --report --verbose --watchfile=debian/watch version=3 http://user42.tuxfamily.org/constant-defer/index.html \ .*/constant-defer-([0-9]+)\.tar\.gz constant-defer-5/debian/copyright0000644000175000017500000000052211524151224015061 0ustar ggggconstant-defer is Copyright 2009, 2010, 2011 Kevin Ryde constant-defer is licensed under the GNU Public License GPL version 3 or at your option any later version. The complete text of GPL version 3 is in the file /usr/share/common-licenses/GPL-3 The program home page is http://user42.tuxfamily.org/constant-defer/index.html constant-defer-5/debian/control0000644000175000017500000000275111423675255014554 0ustar gggg# Copyright 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 3, or # (at your option) any later version. # # constant-defer is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with constant-defer. If not, see . # Build-Depends could have the "maximum_tests" modules from META.yml # for more tests, but they're optional author tests really and would # just make the build tools drag in more stuff. Source: libconstant-defer-perl Section: perl Priority: optional Build-Depends: cdbs, debhelper (>= 5), libtest-more-perl | perl (>= 5.6.2) Maintainer: Kevin Ryde Standards-Version: 3.9.1 Homepage: http://user42.tuxfamily.org/constant-defer/index.html Bugs: mailto:user42@zip.com.au Package: libconstant-defer-perl Architecture: all Depends: perl, ${perl:Depends}, ${misc:Depends} Description: Constant subs with deferred value calculation constant::defer creates constants like constant.pm, but with the value calculated only on the first call. This can save work for values only needed sometimes. constant-defer-5/lib/0002755000175000017500000000000011525332617012465 5ustar ggggconstant-defer-5/lib/constant/0002755000175000017500000000000011525332617014316 5ustar ggggconstant-defer-5/lib/constant/defer.pm0000644000175000017500000003267411525054534015752 0ustar gggg# Copyright 2008, 2009, 2010, 2011 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # constant-defer is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . package constant::defer; use strict; use vars qw($VERSION); $VERSION = 5; sub import { my $class = shift; $class->_create_for_package (scalar(caller), @_); } sub _create_for_package { my $class = shift; my $target_package = shift; while (@_) { my $name = shift; if (ref $name eq 'HASH') { unshift @_, %$name; next; } unless (@_) { require Carp; Carp::croak ("Missing value sub for $name"); } my $subr = shift; ### $constant::defer::DEBUG_LAST_SUBR = $subr; my ($fullname, $basename); if ($name =~ /::([^:]*)$/s) { $fullname = $name; $basename = $1; } else { $basename = $name; $fullname = "${target_package}::$name"; } ## print "constant::defer $arg -- $fullname $basename $old\n"; $class->_validate_name ($basename); $class->_create_fullname ($fullname, $subr); } } sub _create_fullname { my ($class, $fullname, $subr) = @_; my $run = sub { unshift @_, $fullname, $subr; goto &_run; }; my $func = sub () { unshift @_, \$run; goto $run; }; no strict 'refs'; *$fullname = $func; ### $constant::defer::DEBUG_LAST_RUNNER = $run; } sub _run { my $fullname = shift; my $subr = shift; my $run_ref = shift; ### print "_run() $fullname $subr\n"; my @ret = &$subr(@_); if (@ret == 1) { # constant.pm has an optimization to make a constant by storing a scalar # value directly into the %{Foo::Bar::} hash if there's no typeglob for # the name yet. But that doesn't apply here, there's always a glob from # having converted a function. # # The function created only has name __ANON__ in its coderef GV (as # fetched by Sub::Identify for instance). This is the same as most # function creating modules, including Memoize.pm. Plain constant.pm # likewise, except when it uses the scalar ref in symbol table # optimization, in that case a later upgrade to a function gets a name. # my $value = $ret[0]; $subr = sub () { $value }; } elsif (@ret == 0) { $subr = \&_nothing; } else { $subr = sub () { @ret }; } $$run_ref = $subr; { no strict 'refs'; local $^W = 0; # no warnings 'redefine'; eval { *$fullname = $subr } or die $@; } goto $subr; } # not as strict as constant.pm sub _validate_name { my ($class, $name) = @_; if ($name =~ m{[()] # no parens like CODE(0x1234) if miscounted args |^[0-9] # no starting with a number |^$ # not empty }x) { require Carp; Carp::croak ("Constant name '$name' is invalid"); } } sub _nothing () { } ## no critic (ProhibitSubroutinePrototypes) 1; __END__ =for stopwords bareword stringizing inline there'd fakery subclassing Ryde multi-value inlined coderef subrs subr =head1 NAME constant::defer -- constant subs with deferred value calculation =for test_synopsis my ($some,$thing,$an,$other); =head1 SYNOPSIS use constant::defer FOO => sub { return $some + $thing; }, BAR => sub { return $an * $other; }; use constant::defer MYOBJ => sub { require My::Class; return My::Class->new_thing; } =head1 DESCRIPTION C creates a subroutine which on the first call runs given code to calculate its value, and on the second and subsequent calls just returns that value, like a constant. The value code is discarded once run, allowing it to be garbage collected. Deferring a calculation is good if it might take a lot of work or produce a big result, but is only needed sometimes or only well into a program run. If it's never needed then the value code never runs. A deferred constant is generally not inlined or folded (see L) like a plain C since it's not a single scalar value. In the current implementation a deferred constant becomes a plain one after the first use, so may inline etc in code compiled after that (see L below). =head2 Uses Here are some typical uses. =over 4 =item * A big value or slow calculation only sometimes needed, use constant::defer SLOWVALUE => sub { long calculation ...; return $result; }; if ($option) { print "s=", SLOWVALUE, "\n"; } =item * A shared object instance created when needed then re-used, use constant::defer FORMATTER => sub { return My::Formatter->new }; if ($something) { FORMATTER()->format ... } =item * The value code might load requisite modules too, again deferring that until actually needed, use constant::defer big => sub { require Some::Big::Module; return Some::Big::Module->create_something(...); }; =item * Once-only setup code can be created with no return value. The code is garbage collected after the first run and becomes a do-nothing. Remember to have an empty return statement so as not to keep the last expression's value alive forever. use constant::defer MY_INIT => sub { many lines of setup code ...; return; }; sub new { MY_INIT(); ... } =back =head1 IMPORTS There are no functions as such, everything works through the C import. =over 4 =item C<< use constant::defer NAME1=>SUB1, NAME2=>SUB2, ...; >> The parameters are name/subroutine pairs. For each one a sub called C is created, running the given C the first time its value is needed. C defaults to the caller's package, or a fully qualified name can be given. Remember that the bareword stringizing of C<=E> doesn't act on a qualified name, so add quotes in that case. use constant::defer 'Other::Package::BAR' => sub { ... }; For compatibility with the C module a hash of name/sub arguments is accepted too. But C doesn't need that since there's only ever one thing (a sub) following each name. use constant::defer { FOO => sub { ... }, BAR => sub { ... } }; # works without the hashref too use constant::defer FOO => sub { ... }, BAR => sub { ... }; =back =head1 MULTIPLE VALUES The value sub can return multiple values to make an array style constant sub. use constant::defer NUMS => sub { return ('one', 'two') }; foreach (NUMS) { print $_,"\n"; } The value sub is always run in array context, for consistency, irrespective how the constant is used. The return from the new constant sub is an array style sub () { return @result } If the value sub was a list-style return like C shown above, then this array-style return is slightly different. In scalar context a list return means the last value (like a comma operator), but an array return in scalar context means the number of elements. A multi-value constant won't normally be used in scalar context, so the difference shouldn't arise. The array style is easier for C to implement and is the same as the plain C module does. =head1 ARGUMENTS If the constant is called with arguments then they're passed on to the value sub. This can be good for constants used as object or class methods. Passing anything to plain constants would be unusual. One cute use for a class method style is to make a "singleton" instance of the class. See F in the sources for a complete program. package My::Class; use constant::defer INSTANCE => sub { my ($class) = @_; return $class->new }; package main; $obj = My::Class->INSTANCE; A subclass might want to be careful about letting a subclass object get into the parent C, though if a program only ever used the subclass then that might in fact be desirable. Subs created by C always have prototype C<()>, ensuring they always parse the same way. The prototype has no effect when called as a method like above, but if you want a plain call with arguments then use C<&> to bypass the prototype (see L). &MYCONST ('Some value'); =head1 IMPLEMENTATION Currently C creates a sub under the requested name and when called it replaces that with a new constant sub the same as C would make. This is compact and means that later loaded code might be able to inline it. It's fine to keep a reference to the initial sub and in fact that happens quite normally if importing into another module (with the usual C), or an explicit C<\&foo>, or a C<$package-Ecan('foo')>. The initial sub changes itself to jump to the new constant, it doesn't re-run the value code. The jump is currently done by a C to the new coderef, so it's a touch slower than the new constant sub directly. A spot of XS would no doubt make the difference negligible, in fact perhaps to the point where there'd be no need for a new sub, just have the initial transform itself. If the new form looked enough like a plain constant it might inline in later loaded code. For reference, C (as of version 0.02) considers C subrs as constants, both before and after the first call that runs the value code. C just looks for prototyped S> functions, so any such subr rates as a constant. =head1 OTHER WAYS TO DO IT There's many ways to do "deferred" or "lazy" calculations. =over 4 =item * C makes a function repeat its return. Results are cached against the arguments, so it keeps the original code whereas C discards after the first run. =item * C and friends make a create-once Cinstance> method. C can get close with the fakery shown under L above, though without a C to query. =item * C offers some syntactic sugar for redefining the running subroutine, including to a constant. =item * C can create an instance function for a class. It's geared towards objects and so won't allow 0 or C as the return value. =item * A scalar can be rigged up to run code on its first access. C uses a C. C and C use C on an object. C optimizes out the object from C after the first run. C uses XS magic removed after the first fetch and some parsing for syntactic sugar. The advantage of a variable is that it interpolates in strings, but it won't inline in later loaded code; sloppy XS code might bypass the magic; and package variables aren't very friendly when subclassing. =item * C and C rig up an object wrapper to load and create an actual object only when a method is called, dispatching to it and replacing the callers C<$_[0]>. The advantage is you can pass the wrapper object around, etc, deferring creation to an even later point than a sub or scalar can. =item * C, C and C help make a defer class which transforms lazy stub objects to real ones when a method call is made. A separate defer class is required for each real class. =item * C sets up a run-once code block, but with no particular return value and not discarding the code after run. =item * C and C load code on a class method call such as object creation. They're more about module loading than a defer of a particular value. =item * C and C makes an array calculate values on-demand from a generator function. C does a similar thing for hashes. C hides a function behind a scalar; its laziness is in the argument evaluation, the function is called every time. =back =head1 SEE ALSO L, L, L L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L =head1 HOME PAGE http://user42.tuxfamily.org/constant-defer/index.html =head1 COPYRIGHT Copyright 2009, 2010, 2011 Kevin Ryde constant-defer is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. constant-defer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with constant-defer. If not, see . =cut constant-defer-5/xt/0002755000175000017500000000000011525332617012352 5ustar ggggconstant-defer-5/xt/0-Test-DistManifest.t0000755000175000017500000000232711523640140016177 0ustar gggg#!/usr/bin/perl -w # 0-Test-DistManifest.t -- run Test::DistManifest if available # Copyright 2009, 2010, 2011 Kevin Ryde # 0-Test-DistManifest.t is shared by several distributions. # # 0-Test-DistManifest.t is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as published # by the Free Software Foundation; either version 3, or (at your option) any # later version. # # 0-Test-DistManifest.t is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this file. If not, see . use 5.006; use strict; use warnings; use Test::More; # This is only an author test really and it only really does much in a # working directory where newly added files will exist. In a dist dir # something would have to be badly wrong for the manifest to be off. eval { require Test::DistManifest } or plan skip_all => "due to Test::DistManifest not available -- $@"; Test::DistManifest::manifest_ok(); exit 0; constant-defer-5/xt/0-META-read.t0000755000175000017500000001071611523640141014331 0ustar gggg#!/usr/bin/perl -w # 0-META-read.t -- check META.yml can be read by various YAML modules # Copyright 2009, 2010, 2011 Kevin Ryde # 0-META-read.t is shared among several distributions. # # 0-META-read.t is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # 0-META-read.t is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this file. If not, see . use 5.006; use strict; use warnings; use Test::More; use lib 't'; use MyTestHelpers; BEGIN { MyTestHelpers::nowarnings() } # When some of META.yml is generated by explicit text in Makefile.PL it can # be easy to make a mistake in the syntax, or indentation, etc, so the idea # here is to check it's readable from some of the YAML readers. # # The various readers differ in how strictly they look at the syntax. # There's no attempt here to say one of them is best or tightest or # whatever, just see that they all work. # # See 0-Test-YAML-Meta.t for Test::YAML::Meta which looks into field # contents, as well as maybe the YAML formatting. my $meta_filename; # allow for ancient perl, maybe eval { require FindBin; 1 } # new in 5.004 or plan skip_all => "FindBin not available -- $@"; eval { require File::Spec; 1 } # new in 5.005 or plan skip_all => "File::Spec not available -- $@"; diag "FindBin $FindBin::Bin"; $meta_filename = File::Spec->catfile ($FindBin::Bin, File::Spec->updir, 'META.yml'); -e $meta_filename or plan skip_all => "$meta_filename doesn't exist -- assume this is a working directory not a dist"; plan tests => 5; SKIP: { eval { require YAML; 1 } or skip "due to YAML module not available -- $@", 1; my $ok = eval { YAML::LoadFile ($meta_filename); 1 } or diag "YAML::LoadFile() error -- $@"; ok ($ok, "Read $meta_filename with YAML module"); } # YAML 0.68 is in fact YAML::Old, or something weird -- don't think they can # load together # # SKIP: { # eval { require YAML::Old; 1 } # or skip 'due to YAML::Old not available -- $@', 1; # # eval { YAML::Old::LoadFile ($meta_filename) }; # is ($@, '', # "Read $meta_filename with YAML::Old"); # } SKIP: { eval { require YAML::Syck; 1 } or skip "due to YAML::Syck not available -- $@", 1; my $ok = eval { YAML::Syck::LoadFile ($meta_filename); 1 } or diag "YAML::Syck::LoadFile() error -- $@"; ok ($ok, "Read $meta_filename with YAML::Syck"); } SKIP: { eval { require YAML::Tiny; 1 } or skip "due to YAML::Tiny not available -- $@", 1; my $ok = eval { YAML::Tiny->read ($meta_filename); 1 } or diag "YAML::Tiny->read() error -- $@"; ok ($ok, "Read $meta_filename with YAML::Tiny"); } SKIP: { eval { require YAML::XS; 1 } or skip "due to YAML::XS not available -- $@", 1; my $ok = eval { YAML::XS::LoadFile ($meta_filename); 1 } or diag "YAML::XS::LoadFile() error -- $@"; ok ($ok, "Read $meta_filename with YAML::XS"); } # Parse::CPAN::Meta describes itself for use on "typical" META.yml, so not # sure if demanding it works will more exercise its subset of yaml than the # correctness of our META.yml. At any rate might like to know if it fails, # so as to avoid tricky yaml for everyone's benefit, maybe. # SKIP: { eval { require Parse::CPAN::Meta; 1 } or skip "due to Parse::CPAN::Meta not available -- $@", 1; my $ok = eval { Parse::CPAN::Meta::LoadFile ($meta_filename); 1 } or diag "Parse::CPAN::Meta::LoadFile() error -- $@"; ok ($ok, "Read $meta_filename with Parse::CPAN::Meta::LoadFile"); } # Data::YAML::Reader 0.06 doesn't like header "--- #YAML:1.0" with the # # part produced by other YAML writers, so skip for now # # SKIP: { # eval { require Data::YAML::Reader; 1 } # or skip 'due to Data::YAML::Reader not available -- $@', 1; # # my $reader = Data::YAML::Reader->new; # open my $fh, '<', $meta_filename # or die "Cannot open $meta_filename"; # my $str = do { local $/=undef; <$fh> }; # close $fh or die; # # # if ($str !~ /\.\.\.$/) { # # $str .= "..."; # # } # my @lines = split /\n/, $str; # push @lines, "..."; # use Data::Dumper; # print Dumper(\@lines); # # # { local $,="\n"; print @lines,"\n"; } exit 0; constant-defer-5/xt/0-Test-Pod.t0000755000175000017500000000176711523640137014344 0ustar gggg#!/usr/bin/perl -w # 0-Test-Pod.t -- run Test::Pod if available # Copyright 2009, 2010, 2011 Kevin Ryde # 0-Test-Pod.t is shared by several distributions. # # 0-Test-Pod.t is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # 0-Test-Pod.t is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this file. If not, see . use 5.006; use strict; use warnings; use Test::More; # all_pod_files_ok() is new in Test::Pod 1.00 # eval 'use Test::Pod 1.00; 1' or plan skip_all => "due to Test::Pod 1.00 not available -- $@"; Test::Pod::all_pod_files_ok(); exit 0; constant-defer-5/xt/0-Test-YAML-Meta.t0000755000175000017500000000234711523640136015242 0ustar gggg#!/usr/bin/perl -w # 0-Test-YAML-Meta.t -- run Test::YAML::Meta if available # Copyright 2009, 2010, 2011 Kevin Ryde # 0-Test-YAML-Meta.t is shared by several distributions. # # 0-Test-YAML-Meta.t is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 3, or (at your option) any later # version. # # 0-Test-YAML-Meta.t is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this file. If not, see . use 5.006; use strict; use warnings; use Test::More; my $meta_filename = 'META.yml'; unless (-e $meta_filename) { plan skip_all => "$meta_filename doesn't exist -- assume this is a working directory not a dist"; } # Test::YAML::Meta version 0.15 for upper case "optional_features" names # eval 'use Test::YAML::Meta 0.15; 1' or plan skip_all => "due to Test::YAML::Meta 0.15 not available -- $@"; Test::YAML::Meta::meta_yaml_ok(); exit 0; constant-defer-5/xt/0-Test-Synopsis.t0000755000175000017500000000200211523640137015430 0ustar gggg#!/usr/bin/perl -w # 0-Test-Synopsis.t -- run Test::Synopsis if available # Copyright 2009, 2010, 2011 Kevin Ryde # 0-Test-Synopsis.t is shared by several distributions. # # 0-Test-Synopsis.t is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 3, or (at your option) any later # version. # # 0-Test-Synopsis.t is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this file. If not, see . use 5.006; use strict; use warnings; use Test::More; eval 'use Test::Synopsis; 1' or plan skip_all => "due to Test::Synopsis not available -- $@"; ## no critic (ProhibitCallsToUndeclaredSubs) all_synopsis_ok(); exit 0; constant-defer-5/MANIFEST.SKIP0000644000175000017500000000537211523431323013612 0ustar gggg#!/usr/bin/perl # MANIFEST.SKIP -- my various excluded files # Copyright 2008, 2009, 2010, 2011 Kevin Ryde # This file is shared among several distributions. # # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. # # This file is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this file. If not, see . # cf. /usr/share/perl/5.10/ExtUtils/MANIFEST.SKIP # emacs backups ~$ # emacs locks (^|/)\.# # emacs autosave (^|/)# # own distdir ^[A-Za-z][A-Za-z0-9-_]*-\d+/ # own dist files \.tar$ \.tar\.gz$ \.deb$ # ExtUtils::MakeMaker leaving Makefile.old # and "myman" leaving MANIFEST.old \.old$ # ExtUtils::MakeMaker "metafile" rule temporary, left behind if interrupted ^META_new\.yml$ # built - MakeMaker ^Makefile$ ^blib ^pm_to_blib ^TAGS$ # MakeMaker 6.18 to 6.25, apparently ^blibdirs\.ts$ # msdos compiler output stuff using gcc, # "XSFILENAME.def" extension, and others fixed names it seems \.def$ ^dll\.base$ ^dll\.exp$ # msdos compiler stuff using ms c \.pdb$ # built - recent Module::Build nonsense ^MYMETA\.yml$ # built - cdbs and debhelper ^debian/stamp- ^debian/.*\.log$ # built - texinfo.tex temporaries \.(aux|cp|cps|fn|fns|ky|log|pg|toc|tp|tps|vr)$ # toplevel .c files built from .xs ^[^/]+\.c$ # built .o compiled and .bs from .xs \.o$ \.obj$ \.bs$ # #(^|/)[A-Z][A-Za-z0-9_]*\.c$ #/[^Z])[^/]+\.c$ # built - configury ^a\.out$ ^conftest ^config\.h$ ^myconfig\.h$ # built - toplevel html pages ^[a-zA-Z][^./]+\.html$ # cpantesters reports ^msg\d*\.html$ # inc/MyMakefileExtras.pm "diff-prev" ^diff\.tmp # inc/MyMakefileExtras.pm "lintian-source" ^temp-lintian # some of my im module testing ^tempfile\.png$ # my dists ^dist-deb ^up$ ^c$ # special case pulp test build stuff devel/h2xs/TestConstFoo/ # special case mall executables ^devel/hblk$ ^devel/mallopt$ ^devel/mallstats$ ^devel/malltrim$ # special case fli executables ^devel/mmap-multi$ # special case widget-bits executables ^devel/grandom$ ^devel/grandom-[a-z]+$ # special case widget-cursor executables ^devel/invisible-blank$ # special case x'or executables ^devel/gtk-gc-colour$ # special case ipw and other executables ^devel/misc$ # special case m-i executables ^devel/gen-bits$ # special case combo executables ^devel/toolbutton-overflow-leak$ # special htmlext environs ^test-dist/ \.junk$ \.bak$ ^backup ^misc ^maybe ^samples ^samp ^formats constant-defer-5/Makefile.PL0000755000175000017500000000400511524153326013666 0ustar gggg#!/usr/bin/perl # Copyright 2009, 2011 Kevin Ryde # This file is part of constant-defer. # # constant-defer is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as published # by the Free Software Foundation; either version 3, or (at your option) any # later version. # # constant-defer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with constant-defer. If not, see . use strict; use ExtUtils::MakeMaker; use lib 'inc'; use MyMakeMakerExtras; MyMakeMakerExtras::WriteMakefile (NAME => 'constant::defer', ABSTRACT => 'Constant subs with deferred value calculation.', VERSION_FROM => 'lib/constant/defer.pm', PREREQ_PM => { 'vars' => 0, # for testing ... 'Test' => 0, }, AUTHOR => 'Kevin Ryde ', LICENSE => 'gpl', SIGN => 1, # probably anything MIN_PERL_VERSION => '5', META_MERGE => { resources => { homepage => 'http://user42.tuxfamily.org/constant-defer/index.html', }, optional_features => { maximum_tests => { description => 'Have "make test" do as much as possible.', requires => { 'Scalar::Util' => 0, 'Test::NoWarnings' => 0, }, }, maximum_devel => { description => 'Stuff used variously for development.', requires => { 'base' => 0, 'Data::Dumper' => 0, 'File::Spec' => 0, 'lib::abs' => 0, 'Scalar::Util' => 0, 'warnings' => 0, }, }, }, }, ); constant-defer-5/README0000644000175000017500000000252511257522730012600 0ustar ggggCopyright 2009 Kevin Ryde This file is part of constant-defer. constant-defer is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. constant-defer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with constant-defer. If not, see . constant::defer makes subroutines similar to the builtin constant.pm, but with the value calculation deferred until the sub is actually run. use constant::defer FOO => sub { calculate; return $something }; This is handy for big or slow things only needed sometimes, or where at least the pain can be put off the point needed. Lazy or deferred calculations can be hidden behind a scalar variable too. The choice between a sub and a variable is a matter of style or personal preference. Both ways have advantages, see the constant::defer POD for some notes. The constant-defer home page is http://user42.tuxfamily.org/constant-defer/index.html constant-defer-5/SIGNATURE0000644000175000017500000000630011525332620013172 0ustar ggggThis file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.66. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 842745cb706f8f2126506f544492f7a80dbe29b3 COPYING SHA1 4dcee3b573cfba471cc67e232fad48e866ed9803 Changes SHA1 5c21b6d09b79a898a4d46df969a2853417114577 MANIFEST SHA1 6c771cc4b0718f7bc9c9af01889700d7bce0a8e6 MANIFEST.SKIP SHA1 c1989a95bb3c5f60f62975c0dacc3e269e161dc1 META.yml SHA1 9d7c2681adf05606f256ec7fc4f9f8f714c785f8 Makefile.PL SHA1 16a62183a94aa6d126c0be4a22a28f16b17e8c42 README SHA1 7ab708495db9715a8ec99677ee9189d11709418c debian/changelog SHA1 ac3478d69a3c81fa62e60f5c3696165a4e5e6ac4 debian/compat SHA1 f273b16dce6d913f47d8fcfc23ab2126331ecc30 debian/control SHA1 f4092e23cf1a9d83e70cbb633238c9117a618466 debian/copyright SHA1 0c428f2f76357f42a222b74aa4d01e3dcf82c080 debian/rules SHA1 61652cd1568dcf2614df833eba241755eee34e89 debian/source/format SHA1 7dbe6d7d60aa7d008194241d9ae7d9190c9cf2a4 debian/watch SHA1 51d58edc4faf28e6dadbd6f19796f5f52ef6fbe7 devel/Memoize/ToConstant.pm SHA1 6ba73e607fd311d6fb77332ee61fcb317e7ed92f devel/Memoize/ToConstant.t SHA1 a47696a45185dedbd80dcd43114e08b901c53337 devel/Memoize/t-memoize-toconst-2.pl SHA1 6b881d857b5b9e884dc2bd1b10d2ca587c58c105 devel/Memoize/t-memoize-toconst.pl SHA1 28f9fbc7df6cd5bbecd14377a0046a8687e28d48 devel/MyConstantDeferExport.pm SHA1 7bf6a08cfca4e7ad72ff852815a9bf88edd8c471 devel/Singleton/Const.pm SHA1 d4982d0f3c1fdfe5c13599432a01c9997c370ff0 devel/circular.pl SHA1 3e2ebd33b8fa26a030a51327ebe5eefb483652dc devel/import.pl SHA1 30867f46349b0a9de3362880fc1890e42a9386d1 devel/junk/Attribute-MemoizeToConstant.pm SHA1 9febabcfa584162848315b2f81d4fae18a1096f9 devel/name.pl SHA1 a943324d9e1661f56bacbee4767e41d0e67907f0 devel/package-constants.pl SHA1 7da963e42e7e0d85c5d291ffb84bd150112d15f6 devel/run.pl SHA1 cc54d877973af513bc1648df4afcb0da86effac7 devel/walk.pl SHA1 4acc95b712fa6f06e36707b51cffee153aa783a9 examples/instance.pl SHA1 09b94c5696f2b0cfd7ef15439a26240185aa78e5 examples/simple.pl SHA1 cf647ee28a7aaad9896d0063f8a2529919ccfcd3 inc/MyMakeMakerExtras.pm SHA1 7a988b2aa7ed09f1cb9029a1ef3f0e2139dca0cf inc/my_pod2html SHA1 b7a0e703115138770aa1133d0c6223689a600b51 lib/constant/defer.pm SHA1 36b8eba56c87d62b1b41959187c717577dc16fa5 t/MyTestHelpers.pm SHA1 748fcb89a3d945d8e77986461c27e3b0574ae326 t/constant-defer.t SHA1 0279c9310ec528d10a2a14e602bf98f1c776cce1 xt/0-META-read.t SHA1 8a5e0f34131de34e584fbb1939c191a152566155 xt/0-Test-DistManifest.t SHA1 cc04a5fe5d8b8b38bfd56453d5d2686c8ea58783 xt/0-Test-Pod.t SHA1 8cc52e23427a82cfef5802bf512b13c65de2687a xt/0-Test-Synopsis.t SHA1 4c14845872d6eb4280e12f862d6ba2c343358c60 xt/0-Test-YAML-Meta.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iD8DBQFNVbWQLFMCIV9q3ToRAgNQAKCuE8cdcp+eCx0yCv4BvYRSTU4bIwCfUs3D TrMeF580z1mURdkLwFrdnY0= =wEoa -----END PGP SIGNATURE----- constant-defer-5/META.yml0000644000175000017500000000324111525332617013166 0ustar gggg--- #YAML:1.0 name: constant-defer version: 5 abstract: Constant subs with deferred value calculation. author: - Kevin Ryde license: gpl distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: perl: 5 Test: 0 vars: 0 resources: homepage: http://user42.tuxfamily.org/constant-defer/index.html license: http://www.gnu.org/licenses/gpl.html no_index: directory: - t - inc - devel - examples generated_by: ExtUtils::MakeMaker version 6.55_02 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 optional_features: maximum_devel: description: Stuff used variously for development. requires: base: 0 Data::Dumper: 0 File::Spec: 0 lib::abs: 0 Pod::Simple::HTML: 0 Scalar::Util: 0 warnings: 0 warnings::unused: 0 maximum_tests: description: Have "make test" do as much as possible. requires: File::Spec: 0 FindBin: 0 Parse::CPAN::Meta: 0 Scalar::Util: 0 Test::DistManifest: 0 Test::NoWarnings: 0 Test::Pod: 1.00 Test::Synopsis: 0 Test::YAML::Meta: 0.15 YAML: 0 YAML::Syck: 0 YAML::Tiny: 0 YAML::XS: 0