File: Isa.pm

package info (click to toggle)
libur-perl 0.470%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,192 kB
  • sloc: perl: 61,814; javascript: 255; xml: 108; sh: 13; makefile: 9
file content (48 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package UR::BoolExpr::Template::PropertyComparison::Isa;
use strict;
use warnings;
use UR;
our $VERSION = "0.47"; # UR $VERSION;

UR::Object::Type->define(
    class_name  => __PACKAGE__, 
    is => ['UR::BoolExpr::Template::PropertyComparison'],
);

sub _compare {
    my ($class,$comparison_value,@property_values) = @_;
    
    if (ref $comparison_value) {
        # Reference... maybe an Object?
        local $@;
        if (eval { $comparison_value->isa('UR::Object::Type')} ) {
            # It's a class object.  Compare to the Class's class_name
            $comparison_value = $comparison_value->class_name;
        } else {
            # It's an object... test on that object's type
            $comparison_value = ref($comparison_value);
        }
    }

    foreach my $property_value ( @property_values ) {
        return 1 if (eval { $property_value->isa($comparison_value) });
    }

    return '';
}


1;

=pod

=head1 NAME

UR::BoolExpr::Template::PropertyComparison::Isa - Test whether a value is-a subclass of another class

=head1 DESCRIPTION

If the property returns multiple values, this comparison returns true if any
of the values are a subclass of the comparison value

=cut