DBIx-VersionedSubs
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
205206207208209210211212213214215216217218219220221222223224225
};
(
my
$example_file
=
$main_file
) =~ s!\.pm$!/Examples.pm!;
my
$examples
= `
$perl
-w examples/gen_examples_pod.pl`;
if
(
$examples
) {
warn
"(Re)Creating $example_file\n"
;
$examples
=~ s/\r\n/\n/g;
update_file(
$example_file
,
$examples
);
};
};
sub
update_file {
my
(
$filename
,
$new_content
) =
@_
;
my
$content
;
if
( -f
$filename
) {
open
my
$fh
,
'<:raw:encoding(UTF-8)'
,
$filename
or
die
"Couldn't read '$filename': $!"
;
local
$/;
$content
= <
$fh
>;
};
if
(
$content
ne
$new_content
) {
lib/DBIx/VersionedSubs.pm view on Meta::CPAN
294295296297298299300301302303304305306307308309310311312313314Updates the namespace from the database by loading
all changes.
these will behave weird
if
you redefine a subroutine
that was previously closed over.
=cut
sub update_code {
my ($package) = @_;
my $version = $package->code_version || 0;
#warn "Checking against $version";
my $sth = $package->dbh->prepare_cached(sprintf <<'SQL', $package->code_history);
SELECT distinct name,action,new_code,version FROM %s
WHERE version > ?
ORDER BY version DESC
SQL
$sth->execute($version);
lib/DBIx/VersionedSubs.pm view on Meta::CPAN
360361362363364365366367368369370371372373374375376377378Updates the code
for
the subroutine C<Package::
$name
>
with
the code
given
.
Note that the update only happens in the database, so the change
will only take place on the
next
roundtrip / code refresh.
This cannot
override
subroutines that don't exist in the database.
=cut
sub update_sub {
my ($package,$name,$new_code) = @_;
$package->add_code_history($name,$package->code_source->{$name},$new_code,'U');
my $sth = $package->dbh->prepare_cached(sprintf <<'SQL',$package->code_live);
UPDATE %s SET code=?
WHERE name=?
SQL
$sth->execute($new_code,$name);
};
lib/DBIx/VersionedSubs/AutoLoad.pm view on Meta::CPAN
102103104105106107108109110111112113114115116117118119120121122};
=head2 C<< __PACKAGE__->update_code >>
Overridden to do lazy updates. It wipes all code that
is out of date from the namespace and lets the AUTOLOAD
handler sort out the reloading.
=cut
sub
update_code {
my
(
$package
) =
@_
;
my
$version
=
$package
->code_version || 0;
my
$sth
=
$package
->dbh->prepare_cached(
sprintf
<<'SQL', $package->code_history);
SELECT distinct name,version FROM %s
WHERE version > ?
ORDER BY version DESC
SQL
$sth
->execute(
$version
);
( run in 0.232 second using v1.01-cache-2.11-cpan-bf8d7bb2d05 )