John Drago > Inline-MonoCS > Inline::MonoCS

Download:
Inline-MonoCS-1.000.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.000   Source  

NAME ^

Inline::MonoCS - Use CSharp from Perl, via Mono

SYNOPSIS ^

Hello World

  use Inline::MonoCS
    method        => "HelloWorld",
    compiler_args => "",
    code          => <<"CODE";
  public class HelloWorld
  {
      public static void Main( string[] args)
      {
          System.Console.WriteLine( "Hello, " + args[0] + "!" );
      }
  }
  CODE

  warn HelloWorld("Frank"); # "Hello, Frank!"

Talk to Microsoft SQL Server from Linux

  use Inline::MonoCS
    method        => "ProductCount",
    compiler_args => "-r:System.Data.dll",
    code          => <<'CODE';
  using System;
  using System.Data;
  using System.Data.SqlClient;

  public class ProductCount
  {
      public static void Main(string[] args)
      {
         string connectionString =
            "Server=111.222.111.222;" +
            "Database=northwind;" +
            "User ID=sa;" +
            "Password=s3cr3t;";
         IDbConnection dbcon;
         using (dbcon = new SqlConnection(connectionString)) {
             dbcon.Open();
             using (IDbCommand dbcmd = dbcon.CreateCommand()) {
                 string sql =
                     "SELECT COUNT(*) AS ProductCount " +
                     "FROM Products";
                 dbcmd.CommandText = sql;
                 using (IDataReader reader = dbcmd.ExecuteReader()) {
                     while(reader.Read()) {
                         int ProdCount = Convert.ToInt32( reader["ProdCount"] );
                         Console.WriteLine( ProdCount );
                     }
                 }
             }
         }
      }
  }
  CODE

  my $count = ProductCount();
  warn "We have $count products";

DESCRIPTION ^

This module provides a simple bridge to execute code written in C# from Perl.

It works by compiling your code, then placing the executable under /tmp/ and exporting a subroutine into the calling package. When you call that exported subroutine, the compiled exe is executed and given your arguments on the command-line.

Whatever your program outputs to STDOUT is considered the return value.

AUTHOR ^

Written by John Drago <jdrago_999@yahoo.com>

LICENSE ^

This software is Free software and may be used and redistributed under the same terms as perl itself.

syntax highlighting: