« lib/VSGDR/SQLServer/DataType/Bit.pm
↑ Summary
lib/VSGDR/UnitTest/TestSet/Representation/NET2/CS.pm »
| 1 | package VSGDR::SQLServer::DataType; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | |||
| 8 | #our \$VERSION = '1.01'; | ||
| 9 | use Carp; | ||
| 10 | use parent qw(Clone); | ||
| 11 | |||
| 12 | use overload ( | ||
| 13 | q("") => sub {$_[0]->{VALUE}}, | ||
| 14 | q(0+) => sub {$_[0]->{VALUE}}, | ||
| 15 | '<=>' => \&spaceship, | ||
| 16 | 'cmp' => \&spaceship, | ||
| 17 | ); | ||
| 18 | |||
| 19 | |||
| 20 | our %Types = ( Bit => 1 | ||
| 21 | , Generic => 1 | ||
| 22 | ) ; | ||
| 23 | |||
| 24 | |||
| 25 | sub new { | ||
| 26 | |||
| 27 | local $_ ; | ||
| 28 | |||
| 29 | my $invocant = shift ; | ||
| 30 | my $class = ref($invocant) || $invocant ; | ||
| 31 | |||
| 32 | my @elems = @_ ; | ||
| 33 | my $self = bless {}, $class ; | ||
| 34 | |||
| 35 | $self->_init(@elems) ; | ||
| 36 | return $self ; | ||
| 37 | } | ||
| 38 | |||
| 39 | |||
| 40 | sub _init { | ||
| 41 | |||
| 42 | local $_ ; | ||
| 43 | |||
| 44 | my $self = shift ; | ||
| 45 | my $class = ref($self) || $self ; | ||
| 46 | my $arg = shift ;## can''t check undef !or croak "no _init arg"; | ||
| 47 | |||
| 48 | my $Value = $arg; | ||
| 49 | $self->setValue(${Value} ) ; | ||
| 50 | |||
| 51 | return ; | ||
| 52 | |||
| 53 | } | ||
| 54 | |||
| 55 | sub setValue { | ||
| 56 | |||
| 57 | local $_ ; | ||
| 58 | |||
| 59 | my $self = shift ; | ||
| 60 | my $arg = shift ;## can''t check undef or croak "no setValue arg"; | ||
| 61 | $self->{VALUE} = $arg ; | ||
| 62 | |||
| 63 | } | ||
| 64 | |||
| 65 | sub value { | ||
| 66 | |||
| 67 | local $_ ; | ||
| 68 | |||
| 69 | my $self = shift ; | ||
| 70 | return scalar $self->{VALUE} ; | ||
| 71 | |||
| 72 | } | ||
| 73 | |||
| 74 | ## parent type - do nothing | ||
| 75 | sub quoteValue { | ||
| 76 | local $_ ; | ||
| 77 | my $self = shift ; | ||
| 78 | my $value = shift ; | ||
| 79 | return $value ; | ||
| 80 | } | ||
| 81 | |||
| 82 | ## parent type - do nothing | ||
| 83 | sub unQuoteValue { | ||
| 84 | local $_ ; | ||
| 85 | my $self = shift ; | ||
| 86 | my $value = shift ; | ||
| 87 | return $value ; | ||
| 88 | } | ||
| 89 | |||
| 90 | |||
| 91 | sub make { | ||
| 92 | |||
| 93 | local $_ ; | ||
| 94 | my $self = shift ; | ||
| 95 | my $flagthing = shift or croak 'No object type' ; | ||
| 96 | |||
| 97 | my $objectType ; | ||
| 98 | if ( $flagthing == -7 ) { | ||
| 99 | $objectType = 'Bit'; | ||
| 100 | } | ||
| 101 | else { | ||
| 102 | $objectType = 'Generic'; | ||
| 103 | } | ||
| 104 | croak "Invalid SQL Server Data Type" unless exists $Types{${objectType}}; | ||
| 105 | |||
| 106 | require "VSGDR/SQLServer/DataType/${objectType}.pm"; | ||
| 107 | return "VSGDR::SQLServer::DataType::${objectType}"->new(@_) ; | ||
| 108 | |||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | sub spaceship { | ||
| 113 | my ($s1, $s2, $inverted) = @_; | ||
| 114 | |||
| 115 | return 0 if ( ! defined $s1->value() ) or ( ! defined $s2->value() ) ; | ||
| 116 | return $inverted ? $s2->value() cmp $s1->value() : $s1->value() cmp $s2->value() ; | ||
| 117 | } | ||
| 118 | |||
| 119 | |||
| 120 | 1 ; | ||
| 121 | |||
| 122 | __DATA__ |