| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 6 |  |  | 6 |  | 44 | use strict; | 
|  | 6 |  |  |  |  | 22 |  | 
|  | 6 |  |  |  |  | 189 |  | 
| 2 | 6 |  |  | 6 |  | 34 | use warnings; | 
|  | 6 |  |  |  |  | 12 |  | 
|  | 6 |  |  |  |  | 283 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | # ABSTRACT: Internal value object for the "Unknown::Values" distribution | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | package Unknown::Values::Instance; | 
| 7 |  |  |  |  |  |  | $Unknown::Values::Instance::VERSION = '0.100'; | 
| 8 | 6 |  |  | 6 |  | 32 | use Carp 'confess'; | 
|  | 6 |  |  |  |  | 27 |  | 
|  | 6 |  |  |  |  | 383 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 6 |  |  | 6 |  | 104 | use 5.01000; | 
|  | 6 |  |  |  |  | 21 |  | 
| 11 |  |  |  |  |  |  | my @to_overload; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | BEGIN { | 
| 14 | 6 |  |  | 6 |  | 126 | my %to_overload = ( | 
| 15 |  |  |  |  |  |  | sort        => [qw{ <=> cmp }], | 
| 16 |  |  |  |  |  |  | compare     => [qw{ <= >= < > lt le gt ge == eq != ne}], | 
| 17 |  |  |  |  |  |  | math        => [qw{ + - * / ** atan2 cos sin exp log sqrt int abs }], | 
| 18 |  |  |  |  |  |  | string      => [qw{ qr x }], | 
| 19 |  |  |  |  |  |  | files       => [qw{ <> -X }], | 
| 20 |  |  |  |  |  |  | bits        => [qw{ << >> & | ^ ~ }], | 
| 21 |  |  |  |  |  |  | bool        => [ 'bool', '!' ], | 
| 22 |  |  |  |  |  |  | dereference => [qw< ${} @{} %{} &{} *{} >], | 
| 23 |  |  |  |  |  |  | nomethod    => ['nomethod'], | 
| 24 |  |  |  |  |  |  | ); | 
| 25 | 6 |  |  |  |  | 57 | while ( my ( $method, $ops ) = each %to_overload ) { | 
| 26 | 54 |  |  |  |  | 659 | push @to_overload => $_ => $method foreach @$ops; | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 6 |  |  | 6 |  | 42 | use overload @to_overload, '""' => 'to_string'; | 
|  | 6 |  |  |  |  | 15 |  | 
|  | 6 |  |  |  |  | 98 |  | 
| 31 |  |  |  |  |  |  | my $CORE_UNKNOWN = __PACKAGE__->new; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub to_string { | 
| 34 | 6 |  |  | 6 | 0 | 243 | confess("Attempt to coerce unknown value to a string"); | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub new { | 
| 38 | 15 |  |  | 15 | 0 | 1688 | my $class   = shift; | 
| 39 | 15 |  |  |  |  | 41 | my $unknown = bless {} => $class; | 
| 40 | 15 |  |  |  |  | 34 | return $unknown; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | # this helps to prevent some infinite loops | 
| 44 | 32 |  |  | 32 | 0 | 451 | sub bool {$CORE_UNKNOWN} | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub compare { | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | # this suppresses the "use of unitialized value in sort" warnings | 
| 49 | 26 | 50 |  | 26 | 0 | 153 | wantarray ? () : 0; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub sort { | 
| 53 | 26 | 100 |  | 26 | 0 | 109 | if    ( $_[2] )                                { return -1 } | 
|  | 8 | 100 |  |  |  | 16 |  | 
| 54 | 8 |  |  |  |  | 30 | elsif ( Unknown::Values::is_unknown( $_[1] ) ) { return 0 } # unnecessary? | 
| 55 | 10 |  |  |  |  | 21 | else                                           { return 1 } | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 13 |  |  | 13 | 0 | 16860 | sub math { confess("Math cannot be performed on unknown values") } | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | sub dereference { | 
| 61 | 0 |  |  | 0 | 0 | 0 | confess("Dereferencing cannot be performed on unknown values"); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub files { | 
| 65 | 0 |  |  | 0 | 0 | 0 | confess("File operations cannot be performed on unknown values"); | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | sub string { | 
| 69 | 0 |  |  | 0 | 0 | 0 | confess("String operations cannot be performed on unknown values"); | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | sub bits { | 
| 73 | 4 |  |  | 4 | 0 | 3413 | confess("Bit manipulation cannot be performed on unknown values"); | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub nomethod { | 
| 77 | 0 | 0 |  | 0 | 0 |  | if ( defined( my $operator = $_[3] ) ) { | 
| 78 | 0 |  |  |  |  |  | confess("'$operator' operations are not allowed with unknown values"); | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  | else { | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | # XXX seems bit manipulation can trigger this | 
| 83 | 0 |  |  |  |  |  | confess("Illegal operation performed on unknown value"); | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | 1; | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | __END__ |