0

I am working on a Mason-perl based webapplication and want to intercept a particular url before it hitting the flow and generating the view (I will be having some condition checks and redirect to different URL if that condition met). In spring based mvc we have concept of interceptor which helps us to achieve this. Can some one point out a way how can I achieve this in Mason-perl based webapplication

Sarat
  • 1
  • 1
  • Mason on its own is not MVC. It's just V (as in _view_). How are you using it? Do you use your own route handling, or are you using another web framework with it? You probably have to do that in your dispatcher. Mason itself doesn't provide what you want. See the [source for `run`](https://metacpan.org/source/JSWARTZ/Mason-2.24/lib/Mason/Interp.pm#L358) and [`_make_request`](https://metacpan.org/source/JSWARTZ/Mason-2.24/lib/Mason/Interp.pm#L679). – simbabque Apr 18 '17 at 11:27
  • 1
    I am not familiar with the interceptor concept, maybe do you need something like Mason::Plugin::RouterSimple? Please see this question if it is useful for you http://stackoverflow.com/questions/32353992/specify-route-rules-and-route-to-different-components – fthiella Apr 19 '17 at 12:04
  • @simbabque your comment isn't fully true. Mason usually is used as view, **but** you can use it alone, and it have support for controller parts of the app too. (Enough if you check how the request dispatching works to components, autohandlers and dhandlers). Also, Mason fully supports routing by Mason::Plugin::RouterSimple. All together provides enough powerful "C" part too. :) Read more in older tutorial (the current tutorial it is moved to Poet, but the old is still fully valid): https://metacpan.org/pod/release/JSWARTZ/Mason-2.16/lib/Mason/Manual/Tutorial.pod#MASON-AND-MVC – clt60 Apr 30 '17 at 23:43

1 Answers1

0

The conventional way to do something like that in mason is to utilize autohandlers in the wrapping chain.

If you have a dhandler or .m file, you can add an autohandler file in the same directory to perform the checks before passing off the processing to the other file. If you're already using autohandlers in various places and want to ensure every page has the checks performed, place an autohandler in the root directory and perform the checks there.

For a more comprehensive discussion, see the Mason Book chapter 3 (start with the Autohandlers section).

Avi
  • 1,231
  • 10
  • 23