Permalink
Browse files

converted to twigils

  • Loading branch information...
1 parent 9d52327 commit ade1faaa43dce37ac9fea389d842f73cdfa78bc3 Stevan Little committed Aug 31, 2013
Showing with 416 additions and 397 deletions.
  1. +6 −6 lib/mop/attribute.pm
  2. +4 −4 lib/mop/class.pm
  3. +10 −4 lib/mop/internals/syntax.pm
  4. +3 −3 lib/mop/method.pm
  5. +1 −1 lib/mop/observable.pm
  6. +7 −7 lib/mop/role.pm
  7. +11 −11 t/001-examples/001-point.t
  8. +7 −7 t/001-examples/002-bank-account.t
  9. +10 −10 t/001-examples/003-binary-tree.t
  10. +38 −38 t/001-examples/004-linked-list.t
  11. +4 −4 t/001-examples/005-throwable.t
  12. +3 −3 t/001-examples/007-currency.t
  13. +5 −5 t/001-examples/008-cache.t
  14. +4 −4 t/010-basics/000-basic.t
  15. +4 −4 t/010-basics/001-new.t
  16. +4 −4 t/010-basics/002-new-w-attributes.t
  17. +3 −3 t/010-basics/003-BUILD.t
  18. +4 −4 t/010-basics/005-attribute-override.t
  19. +5 −5 t/010-basics/007-class-methods.t
  20. +3 −3 t/010-basics/010-packages.t
  21. +6 −6 t/010-basics/011-packages-w-exports.t
  22. +6 −6 t/010-basics/020-simple-attributes.t
  23. +6 −6 t/010-basics/021-attributes-w-defaults.t
  24. +6 −6 t/010-basics/022-attributes-w-lazy-defaults.t
  25. +6 −6 t/010-basics/023-attribute-w-lazy-accessor.t
  26. +6 −6 t/010-basics/024-attribute-w-complex-defaults.t
  27. +6 −6 t/010-basics/025-attributes-w-lazy-complex-defaults.t
  28. +5 −5 t/010-basics/026-complex-attributes.t
  29. +12 −12 t/010-basics/027-multi-complex-attributes.t
  30. +8 −8 t/010-basics/040-clone.t
  31. +4 −4 t/030-roles/001-basic.t
  32. +4 −4 t/030-roles/002-compose-into-role.t
  33. +8 −8 t/030-roles/003-multiple-role-compose.t
  34. +1 −1 t/030-roles/005-multiple-classes.t
  35. +2 −2 t/030-roles/006-associated_meta.t
  36. +7 −7 t/030-roles/020-attribute-conflict.t
  37. +1 −1 t/030-roles/021-deep-attribute-conflict.t
  38. +1 −1 t/050-non-mop-integration/002-more-non-mop.t
  39. +3 −3 t/050-non-mop-integration/003-attributes-in-non-mop-inherited-class.t
  40. +3 −3 t/100-internals/002-twigils.t
  41. +1 −1 t/110-oddities/001-syntax-error.t
  42. +7 −2 t/110-oddities/002-lexical-override-attribute.t
  43. +2 −2 t/110-oddities/004-returning-lexicals.t
  44. +11 −3 t/110-oddities/006-order-of-declaration.t
  45. +2 −2 t/110-oddities/013-overriding-attribute-w-param.t
  46. +2 −2 t/110-oddities/015-semicolons-separate.t
  47. +1 −1 t/120-bugs/010-bread-board-bug.t
  48. +4 −4 t/120-bugs/016-github.t
  49. +3 −3 t/150-parser-tests/002-basic.t
  50. +3 −3 t/200-meta/002-meta-w-data.t
  51. +6 −6 t/200-meta/005-associated-class.t
  52. +6 −6 t/200-meta/006-metaclass-cloning.t
  53. +2 −2 t/200-meta/010-extension.t
  54. +6 −6 t/200-meta/011-more-extensions.t
  55. +3 −3 t/200-meta/012-attr-metaclass.t
  56. +2 −2 t/200-meta/020-create-instance-w-meta.t
  57. +10 −10 t/200-meta/101-metaclass-compat-immutable.t
  58. +2 −2 t/400-traits/001-traits.t
  59. +4 −4 t/400-traits/002-class-trait.t
  60. +2 −2 t/400-traits/003-type-trait.t
  61. +3 −3 t/400-traits/004-weaken-trait.t
  62. +6 −6 t/400-traits/005-method-traits.t
  63. +2 −2 t/400-traits/006-overload-trait.t
  64. +2 −2 t/400-traits/007-built-by-trait.t
  65. +10 −10 t/400-traits/008-lazy-trait.t
  66. +6 −6 t/400-traits/020-moose-traits.t
  67. +2 −2 t/500-immutable/002-non-moose-extends.t
  68. +10 −10 t/ext/Option/Option.pm
  69. +19 −19 t/ext/Test-BuilderX/Test/BuilderX.pm
  70. +8 −8 t/ext/Test-BuilderX/Test/BuilderX/Output.pm
  71. +10 −10 t/ext/Test-BuilderX/Test/BuilderX/Test.pm
  72. +5 −5 t/ext/Test-BuilderX/Test/BuilderX/TestPlan.pm
  73. +10 −10 t/ext/Test-BuilderX/Test/BuilderX/Tester.pm
  74. +2 −2 t/lib/Flack/Middleware.pm
  75. +3 −3 t/lib/Flack/Middleware/AccessLog.pm
  76. +2 −2 t/lib/Root.pm
View
@@ -39,7 +39,7 @@ sub name { ${ $name{ $_[0] } } }
sub key_name {
my $self = shift;
- substr( $self->name, 1, length $self->name )
+ substr( $self->name, 2, length $self->name )
}
# NOTE:
@@ -122,28 +122,28 @@ sub __INIT_METACLASS__ {
);
$METACLASS->add_attribute(mop::attribute->new(
- name => '$name',
+ name => '$!name',
storage => \%name
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$original_id',
+ name => '$!original_id',
storage => \%original_id
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$default',
+ name => '$!default',
storage => \%default
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$storage',
+ name => '$!storage',
storage => \%storage,
default => \(sub { init_attribute_storage(my %x) })
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$associated_meta',
+ name => '$!associated_meta',
storage => \%associated_meta
));
View
@@ -177,24 +177,24 @@ sub __INIT_METACLASS__ {
);
$METACLASS->add_attribute(mop::attribute->new(
- name => '$is_abstract',
+ name => '$!is_abstract',
storage => \%is_abstract,
default => \(0)
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$superclass',
+ name => '$!superclass',
storage => \%superclass
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$submethods',
+ name => '$!submethods',
storage => \%submethods,
default => \sub { {} },
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$instance_generator',
+ name => '$!instance_generator',
storage => \%instance_generator,
default => \sub { sub { \(my $anon) } },
));
@@ -3,14 +3,15 @@ package mop::internals::syntax;
use v5.16;
use warnings;
-use Scope::Guard qw[ guard ];
-use Variable::Magic qw[ wizard ];
+use Scope::Guard qw[ guard ];
+use Variable::Magic qw[ wizard ];
use B::Hooks::EndOfScope ();
use Scalar::Util ();
use Sub::Name ();
use Module::Runtime ();
use version ();
+use twigils;
use Parse::Keyword {
class => \&namespace_parser,
@@ -320,7 +321,7 @@ sub generic_method_parser {
# is stored in the fieldhash storage
foreach my $attr (@{ $CURRENT_ATTRIBUTE_LIST }) {
$preamble .=
- 'my ' . $attr . ';'
+ 'twigils::intro_twigil_my_var(q[' . $attr . ']);'
. 'Variable::Magic::cast('
. $attr . ', '
. '(Scalar::Util::blessed($self) '
@@ -382,7 +383,12 @@ sub has_parser {
die "Invalid attribute name " . read_tokenish() unless lex_peek eq '$';
lex_read;
- my $name = '$' . parse_name('attribute');
+ my $twigil = lex_peek;
+ die "Invalid attribute name " . read_tokenish() unless $twigil eq '!' || $twigil eq '.';
+ lex_read;
+
+
+ my $name = '$' . $twigil . parse_name('attribute');
lex_read_space;
View
@@ -72,17 +72,17 @@ sub __INIT_METACLASS__ {
);
$METACLASS->add_attribute(mop::attribute->new(
- name => '$name',
+ name => '$!name',
storage => \%name
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$body',
+ name => '$!body',
storage => \%body
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$associated_meta',
+ name => '$!associated_meta',
storage => \%associated_meta
));
View
@@ -50,7 +50,7 @@ sub __INIT_METACLASS__ {
);
$METACLASS->add_attribute(mop::attribute->new(
- name => '$callbacks',
+ name => '$!callbacks',
storage => \%callbacks
));
View
@@ -249,40 +249,40 @@ sub __INIT_METACLASS__ {
);
$METACLASS->add_attribute(mop::attribute->new(
- name => '$name',
+ name => '$!name',
storage => \%name
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$version',
+ name => '$!version',
storage => \%version
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$authority',
+ name => '$!authority',
storage => \%authority
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$roles',
+ name => '$!roles',
storage => \%roles,
default => \sub { [] },
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$attributes',
+ name => '$!attributes',
storage => \%attributes,
default => \sub { {} },
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$methods',
+ name => '$!methods',
storage => \%methods,
default => \sub { {} },
));
$METACLASS->add_attribute(mop::attribute->new(
- name => '$required_methods',
+ name => '$!required_methods',
storage => \%required_methods,
default => \sub { {} },
));
View
@@ -8,19 +8,19 @@ use Test::More;
use mop;
class Point {
- has $x is ro = 0;
- has $y is ro = 0;
+ has $!x is ro = 0;
+ has $!y is ro = 0;
- method set_x ($new_x) {
- $x = $new_x;
+ method set_x ($x) {
+ $!x = $x;
}
- method set_y ($new_y) {
- $y = $new_y;
+ method set_y ($y) {
+ $!y = $y;
}
method clear {
- ($x, $y) = (0, 0);
+ ($!x, $!y) = (0, 0);
}
method pack {
@@ -31,15 +31,15 @@ class Point {
# ... subclass it ...
class Point3D extends Point {
- has $z is ro = 0;
+ has $!z is ro = 0;
- method set_z ($new_z) {
- $z = $new_z;
+ method set_z ($z) {
+ $!z = $z;
}
method pack {
my $data = $self->next::method;
- $data->{z} = $z;
+ $data->{z} = $!z;
$data;
}
}
@@ -8,26 +8,26 @@ use Test::More;
use mop;
class BankAccount {
- has $balance is ro = 0;
+ has $!balance is ro = 0;
- method deposit ($amount) { $balance += $amount }
+ method deposit ($amount) { $!balance += $amount }
method withdraw ($amount) {
- ($balance >= $amount)
+ ($!balance >= $amount)
|| die "Account overdrawn";
- $balance -= $amount;
+ $!balance -= $amount;
}
}
class CheckingAccount extends BankAccount {
- has $overdraft_account is ro;
+ has $!overdraft_account is ro;
method withdraw ($amount) {
my $overdraft_amount = $amount - $self->balance;
- if ( $overdraft_account && $overdraft_amount > 0 ) {
- $overdraft_account->withdraw( $overdraft_amount );
+ if ( $!overdraft_account && $overdraft_amount > 0 ) {
+ $!overdraft_account->withdraw( $overdraft_amount );
$self->deposit( $overdraft_amount );
}
@@ -10,21 +10,21 @@ use mop;
use Scalar::Util qw[ isweak ];
class BinaryTree {
- has $node is rw;
- has $parent is ro, weak_ref;
- has $left;
- has $right;
+ has $!node is rw;
+ has $!parent is ro, weak_ref;
+ has $!left;
+ has $!right;
- method has_parent { defined $parent }
+ method has_parent { defined $!parent }
- method left { $left //= $class->new( parent => $self ) }
- method has_left { defined $left }
+ method left { $!left //= $class->new( parent => $self ) }
+ method has_left { defined $!left }
- method right { $right //= $class->new( parent => $self ) }
- method has_right { defined $right }
+ method right { $!right //= $class->new( parent => $self ) }
+ method has_right { defined $!right }
}
-my $parent_store = mop::get_meta('BinaryTree')->get_attribute('$parent')->storage;
+my $parent_store = mop::get_meta('BinaryTree')->get_attribute('$!parent')->storage;
{
my $t = BinaryTree->new;
Oops, something went wrong.

0 comments on commit ade1faa

Please sign in to comment.