summaryrefslogtreecommitdiff
path: root/lib/Travel/Status
diff options
context:
space:
mode:
authorDerf Null <derf@finalrewind.org>2023-04-07 13:04:22 +0200
committerDerf Null <derf@finalrewind.org>2023-04-07 13:04:22 +0200
commit809f1910da538bffb0e671eb3965f28d5e60237a (patch)
tree4890b13dcce9cc0643ab255d058fee2d79d4114e /lib/Travel/Status
parent81e0a9ef8a317849dbcc1bafbeb54affc092702c (diff)
move mot mask calculation to a helper function
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm49
1 files changed, 28 insertions, 21 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index e12a76f..da6eb47 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -250,26 +250,6 @@ sub new {
$lid = 'A=1@O=' . $self->{station} . '@';
}
- my $mot_mask = 2**@{ $hafas_instance{$service}{productbits} } - 1;
-
- my %mot_pos;
- for my $i ( 0 .. $#{ $hafas_instance{$service}{productbits} } ) {
- $mot_pos{ $hafas_instance{$service}{productbits}[$i] } = $i;
- }
-
- if ( my @mots = @{ $self->{exclusive_mots} // [] } ) {
- $mot_mask = 0;
- for my $mot (@mots) {
- $mot_mask |= 1 << $mot_pos{$mot};
- }
- }
-
- if ( my @mots = @{ $self->{excluded_mots} // [] } ) {
- for my $mot (@mots) {
- $mot_mask &= ~( 1 << $mot_pos{$mot} );
- }
- }
-
my $maxjny = $conf{results} // 30;
my $duration = $conf{lookahead} // -1;
@@ -289,7 +269,7 @@ sub new {
{
type => "PROD",
mode => "INC",
- value => $mot_mask
+ value => $self->mot_mask
}
]
},
@@ -411,6 +391,33 @@ sub new_p {
# }}}
# {{{ Internal Helpers
+sub mot_mask {
+ my ($self) = @_;
+
+ my $service = $self->{active_service};
+ my $mot_mask = 2**@{ $hafas_instance{$service}{productbits} } - 1;
+
+ my %mot_pos;
+ for my $i ( 0 .. $#{ $hafas_instance{$service}{productbits} } ) {
+ $mot_pos{ $hafas_instance{$service}{productbits}[$i] } = $i;
+ }
+
+ if ( my @mots = @{ $self->{exclusive_mots} // [] } ) {
+ $mot_mask = 0;
+ for my $mot (@mots) {
+ $mot_mask |= 1 << $mot_pos{$mot};
+ }
+ }
+
+ if ( my @mots = @{ $self->{excluded_mots} // [] } ) {
+ for my $mot (@mots) {
+ $mot_mask &= ~( 1 << $mot_pos{$mot} );
+ }
+ }
+
+ return $mot_mask;
+}
+
sub post_with_cache {
my ( $self, $url ) = @_;
my $cache = $self->{cache};