File: 09_autoload.t

package info (click to toggle)
libobject-container-perl 0.16-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 220 kB
  • sloc: perl: 221; makefile: 5
file content (27 lines) | stat: -r--r--r-- 725 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use strict;
use warnings;
use Test::More;

use Carp;
$SIG{__DIE__} = sub { Carp::confess(@_) };

use Object::Container;
my $obj = Object::Container->new;

$obj->autoloader( qr/^Schema::.+/, sub {
    my ($self, $class) = @_;

    my ($table) = $class =~ /^Schema::(.*)/;
    $self->register("Schema::${table}", sub { "Result $table" });
});

ok !$obj->{registered_classes}{'Schema::Foo'}, 'Schema::Foo does not registered';
ok !$obj->{objects}{'Schema::Foo'}, 'Schema::Foo does not initialized';

my $foo = $obj->get('Schema::Foo');
is $foo, 'Result Foo', 'result class ok';

ok $obj->{registered_classes}{'Schema::Foo'}, 'Schema::Foo registered';
ok $obj->{objects}{'Schema::Foo'}, 'Schema::Foo initialized';

done_testing;