DBIx-VersionedSubs

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
    };
    (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

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
Updates the namespace from the database by loading
all changes.
 
Note that if you have/use closures or iterators,
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

360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
Updates 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

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
};
 
=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 )