| 1 | # Copyright (C) 2017 Koha-Suomi | ||
| 2 | # | ||
| 3 | # This file is part of Pootle-Client. | ||
| 4 | |||
| 5 | package Pootle::Filters::Intersection; | ||
| 6 | |||
| 7 | use Modern::Perl '2015'; | ||
| 8 | use utf8; | ||
| 9 | binmode STDOUT, ':encoding(UTF-8)'; | ||
| 10 | binmode STDERR, ':encoding(UTF-8)'; | ||
| 11 | use feature 'signatures'; no warnings "experimental::signatures"; | ||
| 12 | use Carp::Always; | ||
| 13 | use Try::Tiny; | ||
| 14 | use Scalar::Util qw(blessed); | ||
| 15 | |||
| 16 | =head2 Pootle::Filters::Intersection | ||
| 17 | |||
| 18 | Represents an intersection of two Pootle::Resource::* objects based on a common attribute | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | use Params::Validate qw(:all); | ||
| 23 | |||
| 24 | use Pootle::Logger; | ||
| 25 | my $l = bless({}, 'Pootle::Logger'); #Lazy load package logger this way to avoid circular dependency issues with logger includes from many packages | ||
| 26 | |||
| 27 | sub new($class, @params) { | ||
| 28 | $l->debug("Initializing ".__PACKAGE__." with parameters: ".$l->flatten(@params)) if $l->is_debug(); | ||
| 29 | my %self = validate(@params, { | ||
| 30 | obj1 => 1, #eg. a Pootle::Resource::Language-object, | ||
| 31 | obj1Attribute => 1, #eg. "translationProjects", | ||
| 32 | obj2 => 1, #eg. a Pootle::Resource::Project-object, | ||
| 33 | obj2Attribute => 1, #eg. "translationProjects", | ||
| 34 | attributeValue => 1, #eg. "/api/v1/translation-projects/1178/" | ||
| 35 | }); | ||
| 36 | my $s = bless(\%self, $class); | ||
| 37 | |||
| 38 | return $s; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub obj1($s) { return $s->{obj1} } | ||
| 42 | sub obj1Attribute($s) { return $s->{obj1Attribute} } | ||
| 43 | sub obj2($s) { return $s->{obj2} } | ||
| 44 | sub obj2Attribute($s) { return $s->{obj2Attribute} } | ||
| 45 | sub attributeValue($s) { return $s->{attributeValue} } | ||
| 46 | |||
| 47 | =head2 Accessors | ||
| 48 | |||
| 49 | =over 4 | ||
| 50 | |||
| 51 | =item B<obj1> | ||
| 52 | |||
| 53 | =item B<obj1Attribute> | ||
| 54 | |||
| 55 | =item B<obj2> | ||
| 56 | |||
| 57 | =item B<obj2Attribute> | ||
| 58 | |||
| 59 | =item B<attributeValue> | ||
| 60 | |||
| 61 | The common value for both objects | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | 1; |