IOC

 view release on metacpan or  search on metacpan

t/010_IOC_test.t  view on Meta::CPAN

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
        use_ok('IOC::Visitor::SearchForContainer');     
}
 
# test our simple example
 
{
    package FileLogger;
    sub new {
        my ($class, $log_file) = @_;
        ($log_file eq 'logfile.log') || die "Got wrong log file";
        bless { log_file => $log_file } => $class;
    }
     
    package Application;
    sub new {
        my $class = shift;
        bless { logger => undef } => $class
    }
    sub logger {
        my ($self, $logger) = @_;
        (UNIVERSAL::isa($logger, 'FileLogger')) || die "Got wrong logger type";
        $self->{logger} = $logger;
    }
    sub run {}
}      
 
lives_ok {

t/010_IOC_test.t  view on Meta::CPAN

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
      
} '... our simple example ran successfully';
 
# and now test out our complex example
 
{
    package My::FileLogger;
    sub new {
        my ($class, $log_file) = @_;
        (UNIVERSAL::isa($log_file, 'OPEN')) || die "Incorrect Log File";
        bless { log_file => $log_file } => $class;
    }
 
    package My::FileManager;
    sub new {
        my $class = shift;
        bless { } => $class
    }
    sub openFile {
        my ($self, $name) = @_;
        return bless \$name, 'OPEN';
    }
     
    package My::DB;
    sub connect {
        my ($class, $dsn, $u, $p) = @_;
        (defined($dsn) && defined($u) && defined($p)) || die "Database not initialized";
        bless { dsn => $dsn, u => $u, p => $p } => $class;
    }
     
    package My::Application;
    sub new {
        my ($class) = @_;
        bless {
            logger   => undef,
            database => undef
        } => $class
    }

t/030_IOC_Service_test.t  view on Meta::CPAN

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
BEGIN {   
    use_ok('IOC::Service');  
    use_ok('IOC::Container');   
}
 
{ # create a package for a dummy service
    package Logger;
    sub new {
        my $class = shift;
        return bless {} => $class;
    }
}
 
# this function will test that
# we got a container in our
# construction block
sub create_logger {
    my ($container) = @_;
    isa_ok($container, 'IOC::Container');
    return Logger->new();

t/032_IOC_Service_SetterInjection_test.t  view on Meta::CPAN

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
BEGIN {   
    use_ok('IOC::Service::SetterInjection');  
    use_ok('IOC::Container');   
}
 
{ # create a package for a dummy service
    package Logger;
    sub new {
        my ($class) = @_;
        return bless {} => $class;
    }
     
    sub setLogFileHandle {
        my ($self, $file_handle) = @_;
        Test::More::is($file_handle, 'LogFileHandle', '... got the right log file handle');
    }
     
    sub setLogFileFormat {
        my ($self, $file_format) = @_;
        Test::More::is($file_format, 'LogFileFormat', '... got the right log file format');

t/033_IOC_Service_Prototype_test.t  view on Meta::CPAN

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
BEGIN {   
    use_ok('IOC::Service::Prototype');  
    use_ok('IOC::Container');   
}
 
{ # create a package for a dummy service
    package Logger;
    sub new {
        my $class = shift;
        return bless {} => $class;
    }
     
    our $DESTROYED_Loggers = 0;
    sub DESTROY {
       $DESTROYED_Loggers++;
    }
}
 
# this function will test that
# we got a container in our

t/034_IOC_Service_Prototype_ConstructorInjection_test.t  view on Meta::CPAN

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
        my ($class, $file, $format_string) = @_;
        return bless {
            file          => $file,
            format_string => $format_string
            } => $class;
    }
     
    package File;
    sub new {
        my $class = shift;
        bless {} => $class;
    }
}
 
can_ok("IOC::Service::Prototype::ConstructorInjection", 'new');
 
my $service = IOC::Service::Prototype::ConstructorInjection->new('logger' =>
                                ('Logger', 'new' => [
                                    IOC::Service::Prototype::ConstructorInjection->ComponentParameter('file'),
                                    "Log %d %s"
                                ]));

t/035_IOC_Service_Prototype_SetterInjection_test.t  view on Meta::CPAN

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
BEGIN {   
    use_ok('IOC::Service::Prototype::SetterInjection');  
    use_ok('IOC::Container');   
}
 
{ # create a package for a dummy service
    package Logger;
    sub new {
        my ($class) = @_;
        return bless {} => $class;
    }
     
    sub setLogFileHandle {
        my ($self, $file_handle) = @_;
        Test::More::is($file_handle, 'LogFileHandle', '... got the right log file handle');
    }
     
    sub setLogFileFormat {
        my ($self, $file_format) = @_;
        Test::More::is($file_format, 'LogFileFormat', '... got the right log file format');

t/055_IOC_Proxy_Interfaces_test.t  view on Meta::CPAN

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
      
    sub get    {}
    sub set    {}
    sub keys   {}
    sub values {}
     
    package KeyableImpl;
     
    sub new {
        my ($class, %hash) = @_;
        bless \%hash => $class;
    }
     
    sub get    { (shift)->{(shift)} }
    sub set    { (shift)->{(shift)} = shift }   
    sub keys   { keys %{(shift)} }
    sub values { values %{(shift)} }
     
    sub misc_method { return 'misc_method' }
}

t/070_IOC_Parameterized.t  view on Meta::CPAN

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
}
 
{
    package Localized::Object;
     
    use strict;
    use warnings;
     
    sub new {
        my ($class, $locale) = @_;
        bless \$locale => $class;
    }
     
    sub locale { ${$_[0]} }
}
 
my $s = IOC::Service::Parameterized->new('localized_obj' => sub {
    my ($c, %params) = @_;
    Localized::Object->new($params{locale});
});

t/071_IOC_Parameterized_w_Registry.t  view on Meta::CPAN

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
}
 
{
    package Localized::Object;
     
    use strict;
    use warnings;
     
    sub new {
        my ($class, $locale) = @_;
        bless \$locale => $class;
    }
     
    sub locale { ${$_[0]} }
}
 
my $s = IOC::Service::Parameterized->new('localized_obj' => sub {
    my ($c, %params) = @_;
    Localized::Object->new($params{locale});
});

t/100_Test_IOC.t  view on Meta::CPAN

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
}
 
use IOC;
 
{
    package FileLogger;
    sub new {
        my ($class, $log_file) = @_;
        ($log_file eq 'logfile.log') || die "Got wrong log file";
        bless { log_file => $log_file } => $class;
    }
    sub log_file { (shift)->{log_file} }
     
    package Application;
    sub new {
        my $class = shift;
        bless { logger => undef } => $class
    }
    sub logger {
        my ($self, $logger) = @_;
        (UNIVERSAL::isa($logger, 'FileLogger')) || die "Got wrong logger type";
        $self->{logger} = $logger;
    }
    sub run {}
}
 
my $container = IOC::Container->new('moose');



( run in 0.368 second using v1.01-cache-2.11-cpan-94b05bcf43c )