CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: mod_perl:
Extra desktop/mobile selector is appearing while browsing

 



ndhaundiyal
New User

Aug 11, 2014, 2:24 AM

Post #1 of 4 (68620 views)
Extra desktop/mobile selector is appearing while browsing Can't Post

Hi, i have a perl module that detects the device and adds an extra desktop/mobile selector accordingly (test.html -> test.desktop.html). Now, whenever I am moving from one page to another and extra selector is appending (test.desktop.html -> test2.desktop.desktop.html) and because of which I am getting error due to non-existing pages. I want my code to be modified so that if a selector is already present it must not append it again. Given below is the portion doing the above-mentioned task :-


Code
if ($model_group) { 
splice @uri_elements, 1, 0, $model_group;
my $new_uri = join('.', @uri_elements);
debug("New URI: ", $new_uri);
$r->uri($new_uri);
}



Zhris
Enthusiast

Aug 14, 2014, 12:09 PM

Post #2 of 4 (68497 views)
Re: [ndhaundiyal] Extra desktop/mobile selector is appearing while browsing [In reply to] Can't Post

One way could be to put a condition around the splice.


Code
splice @uri_elements, 1, 0, $model_group unless @uri_elements[1] eq $model_group;


This ensures the splice isn't performed if the second uri element is equal to the model group. A regexp may be more suitable if you need to check against multiple model groups:


Code
splice @uri_elements, 1, 0, $model_group unless @uri_elements[1] =~ /^(mobile|desktop)$/;


Lastly, the condition could be better positioned in your code, but I didn't want to hinder the rejoining of the uri elements / updating the uri, inevitably I am uncertain of your intentions beyond this specific problem.

Chris


(This post was edited by Zhris on Aug 14, 2014, 12:23 PM)


ndhaundiyal
New User

Aug 20, 2014, 9:17 PM

Post #3 of 4 (67901 views)
Re: [Zhris] Extra desktop/mobile selector is appearing while browsing [In reply to] Can't Post

@Zhris : I modified the slice statement but that doesn't seems to be working for me. Please let me know if you need further inputs from my end to assist me better on this?


BillKSmith
Veteran

Aug 21, 2014, 6:33 AM

Post #4 of 4 (67810 views)
Re: [ndhaundiyal] Extra desktop/mobile selector is appearing while browsing [In reply to] Can't Post

Perhaps you have to check all the @uri_elements,


Code
use List::Moreutils qw(none); 
#
#
if (none {$_ eq $model_group} @uri_elements) {
splice @uri_elements, 1, 0, $model_group;
}

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives