got some basic tests going and a start at how this is going to come together
[gitmo/MooseX-Attribute-Cached.git] / t / 001_basic.t
CommitLineData
b5552897 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
d0e2ab77 6use Test::More tests => 3;
7use Test::Moose;
8
9BEGIN {
10 use_ok('Moose');
11}
b5552897 12
13=head1 NAME
14
15001_basic.t; tests the overall basic functionality
16
17=head1 DESCRIPTION
18
19Create a L<Moose> class that uses the Caching role and the try out the basic
20functionality. This test uses L<Cache::FastMmap> as the default cache storage
21but you can override that with the following %ENV to test against your local
22L<Cache::Memcached> based caching server:
23
24 TDB write code for %ENV
25
26=head1 TESTS
27
28This package defines the following tests.
29
d0e2ab77 30=head2 Define Test Class
b5552897 31
32Create a class that uses L<MooseX::Attribute::Cached> and has some attributes
33that 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
78Can we create a test instance and make sure it's basic methods work as we
79expect.
80
81=cut
82
83ok my $cached_attrs = MooseX::Attribute::Cached::Test->new()
84 => 'Created a good Object';
85
86isa_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
99Check that the stores the values, that the lazy builders work, that the
100inflater/deflaters work, etc.
101
102=cut
103
104$cached_attrs->manual_config(1);
105$cached_attrs->manual_config(2);
106use Data::Dump qw/dump/;
107
108warn dump $cached_attrs->meta;
109
110=head2 Test Cache Object.
111
112Tests to make sure the Underlying Cached object is behavior as expected.
b5552897 113
114=head1 AUTHOR
115
116John Napiorkowski, C<< <john.napiorkowski at takkle.com> >>
117
118=head1 COPYRIGHT & LICENSE
119
d0e2ab77 120Copyright 2008 John Napiorkowski
b5552897 121
122This program is free software; you can redistribute it and/or modify it
123under the same terms as Perl itself.
124
125=cut
126
1271;