annotate Lib/IMPL/Test.pm @ 79:2d1c3f713280

ORM concept in development
author wizard
date Mon, 05 Apr 2010 00:20:34 +0400
parents 16ada169ca75
children e568c7c8b743
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
1 package IMPL::Test;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
4
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
5 require Exporter;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
6 our @ISA = qw(Exporter);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
7 our @EXPORT_OK = qw(&test &shared &failed &cmparray);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
9 require IMPL::Test::Unit;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
10 use IMPL::Class::Member;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
12 sub test($$) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
13 my ($name,$code) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
14 my $class = caller;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
16 $class->set_meta(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
17 new IMPL::Test::Unit::TestInfo( $name, $code )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
18 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
19 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
20
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
21 sub shared($) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
22 my ($propInfo) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
23
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
24 my $class = caller;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
25
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
26 die new IMPL::Exception("Only properties could be declared as shared",$propInfo->Name) unless eval {$propInfo->isa('IMPL::Class::PropertyInfo')};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
27 die new IMPL::Exception("You can't mark the readonly property as shared",$propInfo->Name) unless $propInfo->canSet;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
28 die new IMPL::Exception("Only public properties could be declared as shared",$propInfo->Name) unless $propInfo->Access == IMPL::Class::Member::MOD_PUBLIC;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
29
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
30 $class->set_meta(new IMPL::Test::Unit::SharedData($propInfo->Name));
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
31 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
32
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
33 sub failed($;@) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
34 die new IMPL::Test::FailException(@_);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
35 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
36
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
37 sub cmparray {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
38 my ($a,$b) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
39
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
40 return 0 unless @$a == @$b;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
41
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
42 for (my $i=0; $i < @$a; $i++ ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
43 return 0 unless $a->[$i] eq $b->[$i];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
44 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
45
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
46 return 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
47 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
48 1;