[libbread-board-perl] 25/66: remove a weird special case in path traversal
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 21:23:34 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libbread-board-perl.
commit c660494fe69d6a2607f368f2618720dd9c679f15
Author: Jesse Luehrs <doy at tozt.net>
Date: Thu Dec 27 16:32:02 2012 -0600
remove a weird special case in path traversal
Previously, given
my $c = container 'Foo', as {
container 'Bar', as {
service 'Baz' => (value => 1);
};
};
you could do $c->fetch('/Foo/Foo/Bar/Bar/Bar/Baz') and still get out the
Baz service, because giving the name of the current container as a path
component was treated as a no-op. This doesn't actually make any sense,
is fairly confusing, and required extra code to implement it as a
special case, so I'm not sure why it was behaving that way at all
originally. So, remove it.
---
lib/Bread/Board/GraphViz.pm | 3 ++-
lib/Bread/Board/Traversable.pm | 6 +-----
t/011_container_path.t | 8 ++++----
t/025_sugar_w_absolute_path.t | 8 ++++----
t/052_parameterized_in_hierarchy.t | 6 +++---
t/100_clone_w_constructor_injection.t | 14 +++++++-------
t/101_clone_w_setter_injection.t | 14 +++++++-------
t/102_clone_w_block_injection.t | 14 +++++++-------
t/110_clone_w_singleton.t | 8 ++++----
t/201_log_dispatch_example.t | 2 +-
t/500_graphviz.t | 18 +++++++++---------
t/lib/graphable.bb | 12 ++++++------
12 files changed, 55 insertions(+), 58 deletions(-)
diff --git a/lib/Bread/Board/GraphViz.pm b/lib/Bread/Board/GraphViz.pm
index 5da6473..c07c1ef 100644
--- a/lib/Bread/Board/GraphViz.pm
+++ b/lib/Bread/Board/GraphViz.pm
@@ -39,7 +39,8 @@ has 'visitor' => (
sub service_name {
my $service = shift;
- return '' unless $service;
+ return '/' . $service->name
+ if $service->parent == $service->get_root_container;
return join '/', service_name($service->parent), $service->name;
}
diff --git a/lib/Bread/Board/Traversable.pm b/lib/Bread/Board/Traversable.pm
index d648271..20dcdbc 100644
--- a/lib/Bread/Board/Traversable.pm
+++ b/lib/Bread/Board/Traversable.pm
@@ -82,11 +82,7 @@ sub _get_container_or_service {
# get_sub_container and get_service is implemented in Container
# there must be a better way to do this
- if ($c->does('Bread::Board::Service')) {
- return $c if $c->name eq $name;
- }
- elsif ($c->isa('Bread::Board::Container')) {
- return $c if $c->name eq $name;
+ if ($c->isa('Bread::Board::Container')) {
return $c->get_sub_container($name) if $c->has_sub_container($name);
return $c->get_service($name) if $c->has_service($name);
}
diff --git a/t/011_container_path.t b/t/011_container_path.t
index 15b4ac7..a68fc27 100644
--- a/t/011_container_path.t
+++ b/t/011_container_path.t
@@ -47,13 +47,13 @@ my $c = Bread::Board::Container->new(
#use Bread::Board::Dumper;
#diag(Bread::Board::Dumper->new->dump($c));
-my $model = $c->fetch('Application/Model');
+my $model = $c->fetch('Model');
isa_ok($model, 'Bread::Board::Container');
is($model->name, 'Model', '... got the right model');
{
- my $model2 = $c->fetch('/Application/Model');
+ my $model2 = $c->fetch('/Model');
isa_ok($model2, 'Bread::Board::Container');
is($model, $model2, '... they are the same thing');
@@ -65,7 +65,7 @@ isa_ok($dsn, 'Bread::Board::Dependency');
is($dsn->service_path, 'dsn', '... got the right name');
{
- my $dsn2 = $c->fetch('/Application/Model/schema/dsn');
+ my $dsn2 = $c->fetch('/Model/schema/dsn');
isa_ok($dsn2, 'Bread::Board::Dependency');
is($dsn, $dsn2, '... they are the same thing');
@@ -76,7 +76,7 @@ isa_ok($root, 'Bread::Board::Container');
is($root, $c, '... got the same container');
-is($model, $model->fetch('../Application/Model'), '... navigated back to myself');
+is($model, $model->fetch('../Model'), '... navigated back to myself');
is($dsn, $model->fetch('../Model/schema/dsn'), '... navigated to dsn');
is($model, $dsn->fetch('../Model'), '... got the model from the dsn');
diff --git a/t/025_sugar_w_absolute_path.t b/t/025_sugar_w_absolute_path.t
index 12fb83c..f23fd47 100644
--- a/t/025_sugar_w_absolute_path.t
+++ b/t/025_sugar_w_absolute_path.t
@@ -31,14 +31,14 @@ my $c = container 'Application' => as {
container 'Controller';
};
-my $model = $c->fetch('Application/Model');
+my $model = $c->fetch('Model');
isa_ok($model, 'Bread::Board::Container');
is($model->name, 'Model', '... got the right model');
{
- my $model2 = $c->fetch('/Application/Model');
+ my $model2 = $c->fetch('/Model');
isa_ok($model2, 'Bread::Board::Container');
is($model, $model2, '... they are the same thing');
@@ -50,7 +50,7 @@ isa_ok($dsn, 'Bread::Board::Dependency');
is($dsn->service_path, 'dsn', '... got the right name');
{
- my $dsn2 = $c->fetch('/Application/Model/schema/dsn');
+ my $dsn2 = $c->fetch('/Model/schema/dsn');
isa_ok($dsn2, 'Bread::Board::Dependency');
is($dsn, $dsn2, '... they are the same thing');
@@ -61,7 +61,7 @@ isa_ok($root, 'Bread::Board::Container');
is($root, $c, '... got the same container');
-is($model, $model->fetch('../Application/Model'), '... navigated back to myself');
+is($model, $model->fetch('../Model'), '... navigated back to myself');
is($dsn, $model->fetch('../Model/schema/dsn'), '... navigated to dsn');
is($model, $dsn->fetch('../Model'), '... got the model from the dsn');
diff --git a/t/052_parameterized_in_hierarchy.t b/t/052_parameterized_in_hierarchy.t
index 7d71d6e..865894e 100644
--- a/t/052_parameterized_in_hierarchy.t
+++ b/t/052_parameterized_in_hierarchy.t
@@ -36,15 +36,15 @@ my $db_conn_info = container 'DatabaseConnection' => as {
};
isa_ok($db_conn_info, 'Bread::Board::Container');
-my $db = $utils->fetch('Utils/Database');
+my $db = $utils->fetch('Database');
isa_ok($db, 'Bread::Board::Container::Parameterized');
isnt(exception {
- $utils->fetch('Utils/Database')->fetch('handle');
+ $utils->fetch('Database')->fetch('handle');
}, undef, '... cannot fetch on a parameterized container');
isnt(exception {
- $utils->fetch('Utils/Database/handle');
+ $utils->fetch('Database/handle');
}, undef, '... cannot fetch within a parameterized container');
my $dbh = $db->create( DBConnInfo => $db_conn_info )->resolve( service => 'handle' );
diff --git a/t/100_clone_w_constructor_injection.t b/t/100_clone_w_constructor_injection.t
index ec8d3ee..978a216 100644
--- a/t/100_clone_w_constructor_injection.t
+++ b/t/100_clone_w_constructor_injection.t
@@ -22,7 +22,7 @@ $board->add_service(
name => 'test',
class => 'Test::Class',
dependencies => {
- dep => Bread::Board::Dependency->new(service_path => '/app/dep'),
+ dep => Bread::Board::Dependency->new(service_path => '/dep'),
},
)
);
@@ -60,12 +60,12 @@ isnt($board->get_service('dep'), $board2->get_service('dep'), '... not the same
# test them ...
-is($board->fetch('/app/dep')->get(), 1, '... got correct dep');
-is($board->fetch('/app/test')->get()->dep, 1, '... test uses dep');
-is(refaddr $board->fetch('/app/test')->parent, refaddr $board, '... got the right board');
+is($board->fetch('/dep')->get(), 1, '... got correct dep');
+is($board->fetch('/test')->get()->dep, 1, '... test uses dep');
+is(refaddr $board->fetch('/test')->parent, refaddr $board, '... got the right board');
-is($board2->fetch('/app/dep')->get(), 2, '... got correct dep');
-is($board2->fetch('/app/test')->get()->dep, 2, '... test uses dep');
-is(refaddr $board2->fetch('/app/test')->parent, refaddr $board2, '... got the right board');
+is($board2->fetch('/dep')->get(), 2, '... got correct dep');
+is($board2->fetch('/test')->get()->dep, 2, '... test uses dep');
+is(refaddr $board2->fetch('/test')->parent, refaddr $board2, '... got the right board');
done_testing;
diff --git a/t/101_clone_w_setter_injection.t b/t/101_clone_w_setter_injection.t
index 1301ac7..b9ad411 100644
--- a/t/101_clone_w_setter_injection.t
+++ b/t/101_clone_w_setter_injection.t
@@ -22,7 +22,7 @@ $board->add_service(
name => 'test',
class => 'Test::Class',
dependencies => {
- dep => Bread::Board::Dependency->new(service_path => '/app/dep'),
+ dep => Bread::Board::Dependency->new(service_path => '/dep'),
},
)
);
@@ -60,12 +60,12 @@ isnt($board->get_service('dep'), $board2->get_service('dep'), '... not the same
# test them ...
-is($board->fetch('/app/dep')->get(), 1, '... got correct dep');
-is($board->fetch('/app/test')->get()->dep, 1, '... test uses dep');
-is(refaddr $board->fetch('/app/test')->parent, refaddr $board, '... got the right board');
+is($board->fetch('/dep')->get(), 1, '... got correct dep');
+is($board->fetch('/test')->get()->dep, 1, '... test uses dep');
+is(refaddr $board->fetch('/test')->parent, refaddr $board, '... got the right board');
-is($board2->fetch('/app/dep')->get(), 2, '... got correct dep');
-is($board2->fetch('/app/test')->get()->dep, 2, '... test uses dep');
-is(refaddr $board2->fetch('/app/test')->parent, refaddr $board2, '... got the right board');
+is($board2->fetch('/dep')->get(), 2, '... got correct dep');
+is($board2->fetch('/test')->get()->dep, 2, '... test uses dep');
+is(refaddr $board2->fetch('/test')->parent, refaddr $board2, '... got the right board');
done_testing;
diff --git a/t/102_clone_w_block_injection.t b/t/102_clone_w_block_injection.t
index e0b9eb3..96b81d6 100644
--- a/t/102_clone_w_block_injection.t
+++ b/t/102_clone_w_block_injection.t
@@ -26,7 +26,7 @@ $board->add_service(
Test::Class->new(%{ $s->params });
},
dependencies => {
- dep => Bread::Board::Dependency->new(service_path => '/app/dep'),
+ dep => Bread::Board::Dependency->new(service_path => '/dep'),
},
)
);
@@ -64,12 +64,12 @@ isnt($board->get_service('dep'), $board2->get_service('dep'), '... not the same
# test them ...
-is($board->fetch('/app/dep')->get(), 1, '... got correct dep');
-is($board->fetch('/app/test')->get()->dep, 1, '... test uses dep');
-is(refaddr $board->fetch('/app/test')->parent, refaddr $board, '... got the right board');
+is($board->fetch('/dep')->get(), 1, '... got correct dep');
+is($board->fetch('/test')->get()->dep, 1, '... test uses dep');
+is(refaddr $board->fetch('/test')->parent, refaddr $board, '... got the right board');
-is($board2->fetch('/app/dep')->get(), 2, '... got correct dep');
-is($board2->fetch('/app/test')->get()->dep, 2, '... test uses dep');
-is(refaddr $board2->fetch('/app/test')->parent, refaddr $board2, '... got the right board');
+is($board2->fetch('/dep')->get(), 2, '... got correct dep');
+is($board2->fetch('/test')->get()->dep, 2, '... test uses dep');
+is(refaddr $board2->fetch('/test')->parent, refaddr $board2, '... got the right board');
done_testing;
diff --git a/t/110_clone_w_singleton.t b/t/110_clone_w_singleton.t
index 7721a10..50dd8b2 100644
--- a/t/110_clone_w_singleton.t
+++ b/t/110_clone_w_singleton.t
@@ -23,7 +23,7 @@ $board->add_service(
name => 'test',
class => 'Test::Class',
dependencies => {
- dep => Bread::Board::Dependency->new(service_path => '/app/dep'),
+ dep => Bread::Board::Dependency->new(service_path => '/dep'),
},
)
);
@@ -38,7 +38,7 @@ isa_ok($board->get_service('dep'), 'Bread::Board::Literal');
## check the singleton-ness
-is($board->fetch('/app/test')->get, $board->fetch('/app/test')->get, '... got the singleton');
+is($board->fetch('/test')->get, $board->fetch('/test')->get, '... got the singleton');
# clone ...
@@ -57,10 +57,10 @@ isnt($board->get_service('dep'), $board2->get_service('dep'), '... not the same
## check the singleton-ness
-is($board2->fetch('/app/test')->get, $board2->fetch('/app/test')->get, '... got the singleton');
+is($board2->fetch('/test')->get, $board2->fetch('/test')->get, '... got the singleton');
## check the singleton-less-ness
-isnt($board->fetch('/app/test')->get, $board2->fetch('/app/test')->get, '... singleton are not shared');
+isnt($board->fetch('/test')->get, $board2->fetch('/test')->get, '... singleton are not shared');
done_testing;
diff --git a/t/201_log_dispatch_example.t b/t/201_log_dispatch_example.t
index 119245e..220e698 100644
--- a/t/201_log_dispatch_example.t
+++ b/t/201_log_dispatch_example.t
@@ -50,7 +50,7 @@ my $c = container 'Logging' => as {
};
};
-my $logger = $c->resolve( service => 'Logging/Logger' );
+my $logger = $c->resolve( service => 'Logger' );
isa_ok($logger, 'Log::Dispatch');
my $screen = $logger->output('screen');
diff --git a/t/500_graphviz.t b/t/500_graphviz.t
index d693b6f..f3c66b4 100644
--- a/t/500_graphviz.t
+++ b/t/500_graphviz.t
@@ -24,15 +24,15 @@ sub cmp_edges {
}
is_deeply [ sort cmp_edges map { [$_->{from}, $_->{to}] } $g->edges ], [
- ['/MyApp/config/config_file' => '/MyApp/name' ],
- ['/MyApp/config/dsn' => '/MyApp/config/config_file'],
- ['/MyApp/config/dsn' => '/MyApp/logger'],
- ['/MyApp/database' => '/MyApp/config/dsn'],
- ['/MyApp/database' => '/MyApp/logger'],
- ['/MyApp/pages/login' => '/MyApp/database'],
- ['/MyApp/pages/login' => '/MyApp/logger'],
- ['/MyApp/pages/login' => '/MyApp/templates/login'],
- ['/MyApp/templates/login' => '/MyApp/config/template_dir'],
+ ['/config/config_file' => '/name' ],
+ ['/config/dsn' => '/config/config_file'],
+ ['/config/dsn' => '/logger'],
+ ['/database' => '/config/dsn'],
+ ['/database' => '/logger'],
+ ['/pages/login' => '/database'],
+ ['/pages/login' => '/logger'],
+ ['/pages/login' => '/templates/login'],
+ ['/templates/login' => '/config/template_dir'],
], 'added all the edges';
done_testing;
diff --git a/t/lib/graphable.bb b/t/lib/graphable.bb
index c59c37a..6cd4e82 100644
--- a/t/lib/graphable.bb
+++ b/t/lib/graphable.bb
@@ -15,7 +15,7 @@ container 'MyApp' => as {
container 'config' => as {
service 'config_file' => (
- dependencies => [ depends_on('/MyApp/name') ],
+ dependencies => [ depends_on('/name') ],
lifecycle => 'Singleton',
block => sub {},
);
@@ -27,7 +27,7 @@ container 'MyApp' => as {
service 'dsn' => (
lifecycle => 'Singleton',
- dependencies => [ depends_on('/MyApp/logger'), depends_on('config_file') ],
+ dependencies => [ depends_on('/logger'), depends_on('config_file') ],
block => sub {},
);
};
@@ -42,7 +42,7 @@ container 'MyApp' => as {
container 'templates' => as {
service 'login' => (
- dependencies => [ depends_on('/MyApp/config/template_dir') ],
+ dependencies => [ depends_on('/config/template_dir') ],
class => 'Template',
block => sub {},
);
@@ -52,9 +52,9 @@ container 'MyApp' => as {
service 'login' => (
class => 'Page::Login',
dependencies => [
- depends_on('/MyApp/templates/login'),
- depends_on('/MyApp/database'),
- depends_on('/MyApp/logger'),
+ depends_on('/templates/login'),
+ depends_on('/database'),
+ depends_on('/logger'),
],
);
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libbread-board-perl.git
More information about the Pkg-perl-cvs-commits
mailing list