Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
package PlusPlus; use strict; use Carp; use vars qw($VERSION); $VERSION = '1.10'; use Filter::Util::Call; sub import { my ($type) = @_; filter_add (bless {oo => 'none', export => [], export_ok => [], is +a => ['Exporter']}); } sub filter { my $self = shift; $_ = translate_oneline ($_, $self) if my ($status) = filter_read ( +); unless ($status) { if ($self -> {oo} eq 'none') { return 0; } else { $_ = ''; $_ .= 'sub new {my $class = shift; my $self = {}; bless ($ +self, $class); eval {init (@_)}; return $self}; '; $_ .= '@ISA = qw(' . join (' ', @{$self -> {isa}}) . '); +@EXPORT = qw(' . join (' ', @{$self -> {export}}) . '); @EXPORT_OK = +qw(' . join (' ', @{$self -> {export_ok}}) . "); 1;\n"; $self -> {oo} = 'none'; return 1; } } return $status; } sub list_to_nested_hashes { my $parts = shift; my $str = shift @$parts; foreach (@$parts) { $str = "\$\{$str\}\{'$_'\}" }; return $str; }; sub list_to_method { my $parts = shift; my $str = shift @$parts; my $method = pop @$parts; $str .= ' -> '; $str .= join (' -> ', (map {"{'$_'}"} @$parts)) . ' -> ' if @$part +s; $str .= $method; return $str; }; sub code_parse_fields_and_methods { return 0 unless shift =~ /([\$]\w+)(\.\$?\w+)+|\$\.\w+(\.\$?\w+)*/ +; my $r = {pre => $`, match => $&, post => $'}; my @parts = split (/\./, $r -> {match}); $r -> {parts} = \@parts; package PlusPlus; use strict; use Carp; use vars qw($VERSION); $VERSION = '1.10'; use Filter::Util::Call; sub import { my ($type) = @_; filter_add (bless {oo => 'none', export => [], export_ok => [], is +a => ['Exporter']}); } sub filter { my $self = shift; $_ = translate_oneline ($_, $self) if my ($status) = filter_read ( +); unless ($status) { if ($self -> {oo} eq 'none') { return 0; } else { $_ = ''; $_ .= 'sub new {my $class = shift; my $self = {}; bless ($ +self, $class); eval {init (@_)}; return $self}; '; $_ .= '@ISA = qw(' . join (' ', @{$self -> {isa}}) . '); +@EXPORT = qw(' . join (' ', @{$self -> {export}}) . '); @EXPORT_OK = +qw(' . join (' ', @{$self -> {export_ok}}) . "); 1;\n"; $self -> {oo} = 'none'; return 1; } } return $status; } sub list_to_nested_hashes { my $parts = shift; my $str = shift @$parts; foreach (@$parts) { $str = "\$\{$str\}\{'$_'\}" }; return $str; }; sub list_to_method { my $parts = shift; my $str = shift @$parts; my $method = pop @$parts; $str .= ' -> '; $str .= join (' -> ', (map {"{'$_'}"} @$parts)) . ' -> ' if @$part +s; $str .= $method; return $str; }; sub code_parse_fields_and_methods { return 0 unless shift =~ /([\$]\w+)(\.\$?\w+)+|\$\.\w+(\.\$?\w+)*/ +; my $r = {pre => $`, match => $&, post => $'}; my @parts = split (/\./, $r -> {match}); $r -> {parts} = \@parts; return $r; }; sub code_translate_fields_and_methods { my $src_line = shift; while (1) { last unless (my $parsed = code_parse_fields_and_methods ($src_ +line)); my $str = ($parsed -> {post} =~ /^\s*\(/ ? list_to_method ($parsed -> {parts}) : list_to_nested_hashes ($parsed -> {parts}) ); $src_line = $parsed -> {pre} . $str . $parsed -> {post} } return $src_line; }; sub code_translate_fields_and_methods { my $src_line = shift; while (1) { last unless (my $parsed = code_parse_fields_and_methods ($src_ +line)); my $str = ($parsed -> {post} =~ /^\s*\(/ ? list_to_method ($parsed -> {parts}) : list_to_nested_hashes ($parsed -> {parts}) ); $src_line = $parsed -> {pre} . $str . $parsed -> {post} } return $src_line; }; sub translate_oneline { local $_ = shift; my $cntxt = shift; if (s/class\s+([\w\:]+)\s*(\([^\)]+\))?\s*\;/package $1; use Expor +ter; use vars qw(\@ISA \@EXPORT \@EXPORT_OK);/) { $cntxt -> {oo} = 'class'; foreach my $ancestor (split /,/, $2) { $ancestor =~ s /[\s\(\)]//g; push @{$cntxt -> {isa}}, $ancestor; } } if (s/module\s+([\w\:]+)\s*(\([^\)]+\))?\s*\;/package $1; use Expo +rter; use vars qw(\@ISA \@EXPORT \@EXPORT_OK);/) { $cntxt -> {oo} = 'module'; foreach my $ancestor (split /,/, $2) { $ancestor =~ s /[\s\(\)]//g; push @{$cntxt -> {isa}}, $ancestor; } } s/method\s+(\w+)\s*\{/sub $1 { my \$self = shift; my \$__with__pre +fix__ = \$self; /; if (s/(export_ok|export)\s+sub\s+(\w+)/sub $2/) { my $name = $2; push @{$cntxt -> {export_ok}}, $name if ($1 eq 'export_ok'); push @{$cntxt -> {export}}, $name if ($1 eq 'export'); } s/new\s+([\w\:]+)/ $1 -> new/g; s/with([^\{]+)\{/do { my \$__with__prefix__ = $1\;/g; s/\$\./\$__with__prefix__\./g; code_translate_fields_and_methods ($_); };

In reply to PlusPlus.pm by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-26 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found