Written by

Senior Development Manager at InterSystems Corporation
Question Timothy Leavitt · May 10, 2023

Is it possible to define an *instance* method in tag-based CSP?

In a tag-based CSP page, I can define (e.g.):

<script method="Foo" language="cache" runat="server">

Is there any way to use this syntax to define an *instance* method (i.e., Method rather than ClassMethod) in the generated class?

Product version: IRIS 2023.1

Comments

Enrico Parisi · May 10, 2023

Supposing it's possible, does it make sense? Note that it's a genuine question, a doubt I have.

What would be the instance (i.e. $this) of the method?

Enrico

0
Timothy Leavitt  May 10, 2023 to Enrico Parisi

That's a fair question. In my specific case, I'm trying to write a tag-based CSP page that extends %CSP.WebSocket, which involves overriding instance methods.

0
Timothy Leavitt · May 10, 2023

Turns out that it's as simple as putting classmethod="0" in your <script> tag... and then getting a helpful error message on compilation that you can't actually do that in a CSP page. 😂

0
Timothy Leavitt  May 10, 2023 to Timothy Leavitt

On the other hand, if you use:

classmethod="##(+$Piece($STACK($STACK-3,"PLACE"),"+",2)<10)##"

Then it'll happily compile instance methods, and your successor and someone in the WRC will have probably a good laugh when your application randomly breaks in 2-10 years.

Preoccupied scientists | Your Scientists Were So Preoccupied With Whether  Or Not They Could, They Didn't Stop To Think If They Should | Know Your Meme

0
Ben Spead  May 10, 2023 to Timothy Leavitt

well played :)

0
Enrico Parisi · May 10, 2023

Create a new class, say myCSP.WebSocket, that extends %CSP.WebSocket.

Add your instance method to myCSP.WebSocket class and use it as superclass of your CSP page(s).

Enrico

0
Timothy Leavitt  May 10, 2023 to Enrico Parisi

This is a much cleaner option, of course. :)

(I have other constraints that led me to not go this route in the first place.)

0
Enrico Parisi · May 10, 2023

In fact, even subclassing %CSP.WebSocket or adding your instance methods class as superclass would not work because all the code you write inside a CSP page run in class methods, so you cannot call an instance method.

And this brings back my initial question:

What would be the instance (i.e. $this) of the method?

None I think, within a CSP page code there is no current instance, the "page" is not instantiated, even when using %CSP.WebSocket as superclass.

But...how are you using %CSP.WebSocket??

Something like:
<CSP:CLASS SUPER="%CSP.WebSocket">

Or what/how?

Enrico

0
Timothy Leavitt  May 16, 2023 to Enrico Parisi

Yes, that was how I was trying to.

0
Alex Woodhead · May 12, 2023

Have used "%" variables to share context between a chain of sequentially executing classmethods on a CSP page.

This means enriching existing %request.Data variable, as it is already there and instrumented for Dump, or can use a different % variable name.

0
Enrico Parisi · May 16, 2023

In a tag-based CSP page...

 just use a class and the CSPURL parameter 

Well, that's a change of the game! 😁

Enrico

0