sub new { die "main::new sub called" } sub Foo { die "main::Foo sub called" } # can't use Foo->new here!!!!!!!!!!! $obj = new Foo:: ; print "Got $obj\n"; package Foo; sub new { return bless [] => shift(); }
That will correctly print out Got Foo=ARRAY(0x7ec91370). There is no ambiguity: you just have to do it right, that’s all. That said, it’s no fun to chain them.
And by the way, the mechanism you used won’t work in the code above. Your style can be just as buggy as what you’re worried about people doing by using dative syntax. If you don’t want to use the package-quoted dative syntax of new Foo::, you still must use Foo::->new and not Foo->new, because otherwise you’ll still bomb out. Please try it with the commented-out line to see what I mean.
And here’s another:my $sorter = new Unicode::Collate:: upper_before_lower => 1, preprocess => \&reduce_for_sorting, entry => deQ<<'END_OF_OVERRIDE', |Q| |Q| 005B 006E 002E ; [.0200.0020.0002.0391] # [n. |Q| 005B ; [.0220.0020.0002.0392] # [ |Q| 005D ; [.0225.0020.0002.0395] # ] |Q| END_OF_OVERRIDE ;
See how nice and legible that is when written that way? And there really and truly is no ambiguity — unlike with your code, where there is.state $formatter = new Unicode::LineBreak:: Context => "NONEASTASIAN", ColumnsMax => 80, ColumnsMin => 8, Format => "SIMPLE", SizingMethod => \&tabbed_sizing, TailorLB => [ ord("\t") => LB_SP, LEFT_QUOTES() => LB_OP, RIGHT_QUOTES() => LB_CL, ], ;
PS: I see my stalker is quick to the draw. Yawn!
In reply to Re^2: Writing Object-Orientated Module: use of “new” and other methods. by tchrist
in thread Writing Object-Orientated Module: use of “new” and other methods. by Anonymous Monk
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data! Titles consisting of a single word are discouraged, and in most cases are disallowed outright. Read Where should I post X? if you're not absolutely sure you're posting in the right place. Please read these before you post! — Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
For: Use: & & < < > > [ [ ] ] Link using PerlMonks shortcuts! What shortcuts can I use for linking? See Writeup Formatting Tips and other pages linked from there for more info.