1#============================================================= -*-perl-*-
2#
3# t/core/hub.t
4#
5# Test the Badger::Hub.pm module.  Run with -d option for debugging.
6#
7# Copyright (C) 2006 Andy Wardley.  All Rights Reserved.
8#
9# This is free software; you can redistribute it and/or modify it
10# under the same terms as Perl itself.
11#
12#========================================================================
13
14use strict;
15use warnings;
16
17use lib qw( core/lib t/core/lib ./lib ../lib ../../lib );
18use Badger::Hub;
19use Badger::Test
20    tests => 6,
21    debug => 'Badger::Hub',
22    args  => \@ARGV;
23
24my $pkg = 'Badger::Hub';
25
26#------------------------------------------------------------------------
27# test class methods
28#------------------------------------------------------------------------
29
30my $p1 = $pkg->prototype();
31my $p2 = $pkg->prototype();
32is( $p1, $p2, 'Hub prototype is a singleton' );
33is( $p1, $Badger::Hub::PROTOTYPE, 'Hub prototype is cache in package' );
34
35$pkg->destroy();
36
37ok( ! defined $Badger::Hub::PROTOTYPE, 'Hub prototype destroyed' );
38
39
40#-----------------------------------------------------------------------
41# check we get methods failing
42#-----------------------------------------------------------------------
43
44eval { $pkg->nothing };
45like( $@, qr/Invalid method 'nothing'/, 'invalid method' );
46
47
48#-----------------------------------------------------------------------
49# subclass to define some components
50#-----------------------------------------------------------------------
51
52package My::Hub;
53use base 'Badger::Hub';
54
55our $COMPONENTS = {
56    widget => 'My::Widget',
57};
58
59package main;
60my $hub    = My::Hub->new;
61my $widget = $hub->widget;
62ok( $widget, 'got widget' );
63is( ref $widget, 'My::Widget', 'got My::Widget' );
64
65
66
67__END__
68
69# Local Variables:
70# mode: perl
71# perl-indent-level: 4
72# indent-tabs-mode: nil
73# End:
74#
75# vim: expandtab shiftwidth=4:
76