Re: Component from a string?

Rolf Schaufelberger <[email protected]> Tue, 8 Jan 2013 00:23:08 +0100
Newsgroups gmane.comp.web.mason.user
Message-ID <[email protected]>
Yes,

Am 07.01.2013 um 22:55 schrieb Allan Engelhardt <[email protected]>:

> Suppose I have a string (from a database or whatever) that I want to compile, run, and insert into the current component - is that possible? Something like (not tested):
> 
> % # test.mc
> <%init>
> my $s = q{<p>I know 1+1=<% 1+1 %>.</p>}; # From external source
> </%init>
> <p>I know many facts</p>
> <% $m->magic( $s ) %>
> 
> for some function magic( ... ) which should probably be called scomp_from_string or somesuch....
> 

for HTML::Mason
see the docs for HTML::Mason::Interp::make_component

# Make an anonymous component
my $anon_comp =
  eval { $interp->make_component
           ( comp_source => '<%perl>my $name = "World";</%perl>Hello <% $name %>!' ) };
die $@ if $@;
 
$m->comp($anon_comp);



> Allan
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. SALE $99.99 this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122412_______________________________________________
> Mason-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mason-users

Mit freundlichen Grüßen
Rolf Schaufelberger

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412

_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users
smime.p7s (application/pkcs7-signature, 4.2 KB) - not displayed