Commit | Line | Data |
b5552897 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
d0e2ab77 |
6 | use Test::More tests => 3; |
7 | use Test::Moose; |
8 | |
9 | BEGIN { |
10 | use_ok('Moose'); |
11 | } |
b5552897 |
12 | |
13 | =head1 NAME |
14 | |
15 | 001_basic.t; tests the overall basic functionality |
16 | |
17 | =head1 DESCRIPTION |
18 | |
19 | Create a L<Moose> class that uses the Caching role and the try out the basic |
20 | functionality. This test uses L<Cache::FastMmap> as the default cache storage |
21 | but you can override that with the following %ENV to test against your local |
22 | L<Cache::Memcached> based caching server: |
23 | |
24 | TDB write code for %ENV |
25 | |
26 | =head1 TESTS |
27 | |
28 | This package defines the following tests. |
29 | |
d0e2ab77 |
30 | =head2 Define Test Class |
b5552897 |
31 | |
32 | Create a class that uses L<MooseX::Attribute::Cached> and has some attributes |
33 | that are cached. |
34 | |
35 | =cut |
36 | |
d0e2ab77 |
37 | { |
38 | ## Stub for the meta attribute trait. |
39 | package MooseX::Attribute::Cached::Meta::Attribute::Trait::Cached; |
40 | use Moose::Role; |
41 | |
42 | has 'cache' => ( |
43 | is=>'ro', |
44 | ); |
45 | |
46 | around 'set_value' => sub { |
47 | my ($set_value, $self, $instance, $value) = @_; |
48 | warn "detected set_value"; |
49 | $self->$set_value($value); |
50 | }; |
51 | |
52 | 1; |
53 | |
54 | ## meta attribute needs registering. |
55 | package Moose::Meta::Attribute::Custom::Trait::Cached; |
56 | sub register_implementation { |
57 | 'MooseX::Attribute::Cached::Meta::Attribute::Trait::Cached'; |
58 | } |
59 | |
60 | 1; |
61 | |
62 | ## Test Class |
63 | |
64 | package MooseX::Attribute::Cached::Test; |
65 | use Moose; |
66 | |
67 | has 'manual_config' => ( |
68 | is=>'rw', |
69 | traits=>['Cached'], |
70 | ); |
71 | |
72 | 1; |
73 | } |
74 | |
75 | |
76 | =head2 Test Instantiation |
77 | |
78 | Can we create a test instance and make sure it's basic methods work as we |
79 | expect. |
80 | |
81 | =cut |
82 | |
83 | ok my $cached_attrs = MooseX::Attribute::Cached::Test->new() |
84 | => 'Created a good Object'; |
85 | |
86 | isa_ok $cached_attrs => 'MooseX::Attribute::Cached::Test' |
87 | => 'Got the correct Object'; |
88 | |
89 | ## Let's create a couple extra instances that all hook up to this given |
90 | ## caching system for attributes. |
91 | |
92 | my @instances = map { |
93 | MooseX::Attribute::Cached::Test->new() |
94 | } (1..5); |
95 | |
96 | |
97 | =head2 Test Cached Attributes. |
98 | |
99 | Check that the stores the values, that the lazy builders work, that the |
100 | inflater/deflaters work, etc. |
101 | |
102 | =cut |
103 | |
104 | $cached_attrs->manual_config(1); |
105 | $cached_attrs->manual_config(2); |
106 | use Data::Dump qw/dump/; |
107 | |
108 | warn dump $cached_attrs->meta; |
109 | |
110 | =head2 Test Cache Object. |
111 | |
112 | Tests to make sure the Underlying Cached object is behavior as expected. |
b5552897 |
113 | |
114 | =head1 AUTHOR |
115 | |
116 | John Napiorkowski, C<< <john.napiorkowski at takkle.com> >> |
117 | |
118 | =head1 COPYRIGHT & LICENSE |
119 | |
d0e2ab77 |
120 | Copyright 2008 John Napiorkowski |
b5552897 |
121 | |
122 | This program is free software; you can redistribute it and/or modify it |
123 | under the same terms as Perl itself. |
124 | |
125 | =cut |
126 | |
127 | 1; |