2

I would want to understand the difference between a .m file and .mi file in Perl/Mason.

As per the mason components docs:

.mi - internal component. An internal component can only be accessed from other components.

I can see that i can call specific methods in written in a .mi file by

$m->comp('test.mi:randomMethod', arg1=> 'blah')

Can i do the same for my .m file as well ? As all the existing places i searched online . i only found a file with no methods and the entire file is executed when called.

$m->comp('test.m', arg1=> 'blah') runs the entire file as it has no methods.

So,

  1. I want to know the difference between both file extensions

  2. Can i have methods similar to .mi file in .m file and call those methods specifically?

  3. When should i choose .m file and when .mi file ?

Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130
achut1993
  • 21
  • 1
  • 6
  • Have you tried? Or are you evaluating whether to use Mason at all before trying? – simbabque May 20 '17 at 08:19
  • There is an exiting .m file which is doing something. It doesnt have any methods. But where as .mi file has methods and specifically those methods alone can be called. is that possible in .m file ? I want to understand before trying them out. – achut1993 May 20 '17 at 08:20
  • I have never used Mason, so I have no idea. I was trying to help you clarify your question. But my suggestion is you just create a new .m file, put a _hello world_ method in it and try. :) – simbabque May 20 '17 at 08:23
  • ok thanks for your help. – achut1993 May 20 '17 at 08:25
  • *"the mason components docs"* Do you mean the documentation for [Mason::Manual::Components](https://metacpan.org/pod/Mason::Manual::Components)? – Borodin May 20 '17 at 20:27

2 Answers2

4

I am kind of new to Mason, but ran into the similar questions before, I'll try my best to answer the questions, but I can be very wrong...

  1. I would want to know the difference between the both file extensions

According to my very limited experience with mason, the .m files are somewhat equivalent to the .mc file, which is a top-level component that serves to a request.

And the .mi files are internal components that carries business logic for helping preparing data/content for the top-level .m file.

  1. Can i have methods similar to .mi file in .m file and call those methods specifically ?

Yes, you can define a method in .m file, can call it just like .mi file, for example:

$m->comp('/foo/bar.m:start')

I've seen working codes doing that.

  1. When should i chose .m file and when .mi file ?

I guess this goes to the differences between .m and .mi files.

For public logic, like pulling an image, you can put the logic in the .m file.

For business logic or dealing with sensitive information, do it in .mi file.

Pang
  • 9,564
  • 146
  • 81
  • 122
Alex
  • 148
  • 1
  • 6
  • @Jolta this looks like a perfectly valid answer. Why flag it as "A different question posted as an answer"? – Al.G. Mar 26 '18 at 11:18
1

I have only ever seen .mp, .mc, and .mi for Mason Perl, Mason Component, and Mason Internal respectively. But they are configurable

If you read PARAMETERS TO THE new() CONSTRUCTOR from the Mason::Interp documentation, you wqill see that you can specify a value for pure_perl_extensions to change the default from .mp, and top_level_extensions for .mc

There's every reason to keep to these standards, unles you are working with two conflicting standards and need one to move out of the way

I don't know whether .mi is required, but it seems unlikely. And I don't remember ever seeing a simple .m. Where have you seen this yourself, and shouldn't it be a .mi file?—i.e. is the example that you have seen an internal component?

Borodin
  • 126,100
  • 9
  • 70
  • 144